public static IModelDiscrete <double, int> Read(BinaryReader reader) { IDataContext data_context = DataSet.DataContext.Read(reader); ModelNearestNeighborKDTreeDefault model = new ModelNearestNeighborKDTreeDefault(data_context); double[][] instance_features = ToolsCollection.ConvertToArrayArray(reader.ReadFloat64Array2D()); bool[][] instance_missings = ToolsCollection.ConvertToArrayArray(new bool[instance_features.GetLength(0), instance_features.GetLength(1)]); int[][] instance_labels = ToolsCollection.ConvertToArrayArray(reader.ReadInt32Array2D()); IDataSet <double, int> training_set = new DataSet <double, int>(data_context, instance_features, instance_missings, instance_labels); return(model.GenerateModelDiscrete(training_set)); }
public IModelDiscreteIterative <double, int> GenerateModelDiscreteIncremental(IDataSet <double, int> training_set) { ModelNearestNeighborKDTreeDefault model = new ModelNearestNeighborKDTreeDefault(training_set.DataContext); IList <Tuple <double[], int> > training_instances = new List <Tuple <double[], int> >(); for (int instance_index = 0; instance_index < training_set.InstanceCount; instance_index++) { training_instances.Add(new Tuple <double[], int>(training_set.GetInstanceFeatureData(instance_index), training_set.GetInstanceLabelData(instance_index)[0])); } model.Add(training_instances); return(model); }
public static void Write(BinaryWriter writer, ModelNearestNeighborKDTreeDefault model) { model.DataContext.Write(writer); IList <Tuple <double[], int> > list = model.Values(); double[,] instance_features = new double[list.Count, model.DataContext.FeatureCount]; int[] instance_labels = new int[list.Count]; for (int instance_index = 0; instance_index < list.Count; instance_index++) { instance_features.Set1DIndex1(instance_index, list[instance_index].Item1); instance_labels[instance_index] = list[instance_index].Item2; } writer.Write(instance_features); writer.Write(instance_labels); }