[Solved]Given Pointhpp Kdthpp Classes Need Help Implementing Ifndef Pointhpp Define Pointhpp Inclu Q37214078
Given Point.hpp and KDT.hpp classes I need help withimplementing the
#ifndef Point_hpp
#define Point_hpp
#include // pow, abs
#include // vector
#include
using namespace std;
#define DELTA 0.00005
/** The data point with given features and label **/
class Point {
public:
vector features;
int label;
int numDim;
double squareDistToQuery;
/** Default constructor */
Point() {}
/** TODO: Constructor that defines a datapoint with features and certain
label */
Point(vector features, int label) {
this->label = label;
this->features = features;
}
/** Set the square distance to current querypoint */
/** sets current point’s (this)squareDistToQuery member variable to calculated
* distance between this point andqueryPoint param
* @param queryPoint the query point inwhich we are comparing against
* for distance
**/
void setSquareDistToQuery(const Point&queryPoint) {
//TODO
int temp = 0;
for(int i = 0; i <features.size(); i++) {
temp +=((features[i] – queryPoint.features[i]) *
(features[i] – queryPoint.features[i]));
}
this->squareDistToQuery = temp;
}
/** Equals operator */
bool operator == (const Point& other) const{
if (numDim !=other.numDim) return false;
for (int i = 0; i <numDim; i++) {
if (abs(features[i] – other.features[i]) > DELTA) {
return false;
}
}
return true;
}
/** Not-equals operator */
bool operator != (const Point& other) const{
return !((*this) ==other);
}
};
std::ostream& operator << (std::ostream& out,const Point& data) {
std::string s = “(“;
for (int i = 0; i < data.numDim – 1; i++){
s +=to_string(data.features[i]) + “, “;
}
s += to_string(data.features[data.numDim – 1]) +”) : “
+to_string(data.label);
out << s;
return out;
}
/** The comparator used in sorting points based on valueson
certain dimension */
struct CompareValueAt {
int dimension;
CompareValueAt(int dimension) {
this->dimension =dimension;
}
bool operator() (const Point & p1, constPoint & p2) {
returnp1.features[dimension] < p2.features[dimension];
}
};
#endif /* Point_hpp */
Need help with the buildSubtree() function in the KDT.hpp file
#ifndef KDT_HPP
#define KDT_HPP
#include <algorithm> // sort, max, min
#include <math.h> // pow, abs
#include <vector> //vector<typename>
#include “Point.hpp”
#include <iostream>
using namespace std;
/** A KD tree that can output K nearest neighbors of given querypoint */
class KDT {
protected:
/** Inner class that defines a KDNode withcertain data point
* and pointers to its children andparent
*/
class KDNode {
public:
KDNode * left;
KDNode * right;
KDNode * parent;
Point point;
KDNode() {}
KDNode(Point point) :point(point) {}
};
KDNode * root; // root of KD tree
unsigned int numDim; // number of dimension ofdata points
unsigned int k; // number of nearest neighborsto find
double threshold; // largest distance to querypoint in current KNN
unsigned int isize;
unsigned int iheight;
// TODO: define a data structure to storecurrent K nearest neighbors
vector<Point> kNearestNeighbors;
public:
/** TODO: Default constructor of KD tree*/
KDT(): root(0), numDim(0), k(0),threshold(0.0), isize(0), iheight(0) { }
/** Build the KD tree from the given vectorof Point references */
void build(vector<Point>& points){
// TODO
if(points.size() != 0){
root =buildSubtree(points, 0, points.size()-1, 0, 0);
}
}
/** Find k nearest neighbors of the givenquery point */
vector<Point> findKNearestNeighbors(PointqueryPoint, unsigned int k) {
// TODO
return {};
}
/** Return the size of the KD tree */
unsigned int size() {
return isize;
}
/** Return the height of the KD tree */
unsigned int height() {
return iheight;
}
private:
/** Helper method to recursively build thesubtree of KD tree. */
KDNode * buildSubtree(vector<Point>&points, unsigned int start,
unsigned int end, unsigned int d, unsigned int height) {
//Todo
}
};
#endif // KDT_HPP
Expert Answer
Answer to Given Point.hpp and KDT.hpp classes I need help with implementing the #ifndef Point_hpp #define Point_hpp #include // po… . . .
OR

