Changeset 15227 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis
- Timestamp:
- 07/13/17 11:33:55 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/TSNEAlgorithm.cs
r15225 r15227 58 58 59 59 #region parameter names 60 private const string Distance ParameterName = "DistanceFunction";60 private const string DistanceFunctionParameterName = "DistanceFunction"; 61 61 private const string PerplexityParameterName = "Perplexity"; 62 62 private const string ThetaParameterName = "Theta"; … … 70 70 private const string SetSeedRandomlyParameterName = "SetSeedRandomly"; 71 71 private const string SeedParameterName = "Seed"; 72 private const string Classes ParameterName = "ClassNames";72 private const string ClassesNameParameterName = "ClassesName"; 73 73 private const string NormalizationParameterName = "Normalization"; 74 74 private const string UpdateIntervalParameterName = "UpdateInterval"; … … 93 93 get { return Parameters[NewDimensionsParameterName] as IFixedValueParameter<IntValue>; } 94 94 } 95 public IConstrainedValueParameter<IDistance<double[]>> Distance Parameter {96 get { return Parameters[Distance ParameterName] as IConstrainedValueParameter<IDistance<double[]>>; }95 public IConstrainedValueParameter<IDistance<double[]>> DistanceFunctionParameter { 96 get { return Parameters[DistanceFunctionParameterName] as IConstrainedValueParameter<IDistance<double[]>>; } 97 97 } 98 98 public IFixedValueParameter<IntValue> MaxIterationsParameter { … … 120 120 get { return Parameters[SeedParameterName] as IFixedValueParameter<IntValue>; } 121 121 } 122 public IConstrainedValueParameter<StringValue> Classes Parameter {123 get { return Parameters[Classes ParameterName] as IConstrainedValueParameter<StringValue>; }122 public IConstrainedValueParameter<StringValue> ClassesNameParameter { 123 get { return Parameters[ClassesNameParameterName] as IConstrainedValueParameter<StringValue>; } 124 124 } 125 125 public IFixedValueParameter<BoolValue> NormalizationParameter { … … 132 132 133 133 #region Properties 134 public IDistance<double[]> Distance {135 get { return Distance Parameter.Value; }134 public IDistance<double[]> DistanceFunction { 135 get { return DistanceFunctionParameter.Value; } 136 136 } 137 137 public double Perplexity { … … 179 179 set { SeedParameter.Value.Value = value; } 180 180 } 181 public string Classes {182 get { return Classes Parameter.Value != null ? ClassesParameter.Value.Value : null; }183 set { Classes Parameter.Value.Value = value; }181 public string ClassesName { 182 get { return ClassesNameParameter.Value != null ? ClassesNameParameter.Value.Value : null; } 183 set { ClassesNameParameter.Value.Value = value; } 184 184 } 185 185 public bool Normalization { … … 210 210 public TSNEAlgorithm() { 211 211 var distances = new ItemSet<IDistance<double[]>>(ApplicationManager.Manager.GetInstances<IDistance<double[]>>()); 212 Parameters.Add(new ConstrainedValueParameter<IDistance<double[]>>(Distance ParameterName, "The distance function used to differentiate similar from non-similar points", distances, distances.OfType<EuclideanDistance>().FirstOrDefault()));212 Parameters.Add(new ConstrainedValueParameter<IDistance<double[]>>(DistanceFunctionParameterName, "The distance function used to differentiate similar from non-similar points", distances, distances.OfType<EuclideanDistance>().FirstOrDefault())); 213 213 Parameters.Add(new FixedValueParameter<DoubleValue>(PerplexityParameterName, "Perplexity-parameter of tSNE. Comparable to k in a k-nearest neighbour algorithm. Recommended value is floor(number of points /3) or lower", new DoubleValue(25))); 214 214 Parameters.Add(new FixedValueParameter<PercentValue>(ThetaParameterName, "Value describing how much appoximated " + … … 229 229 230 230 //Name of the column specifying the class lables of each data point.If the label column can not be found training/test is used as labels." 231 Parameters.Add(new OptionalConstrainedValueParameter<StringValue>(Classes ParameterName, "Name of the column specifying the class lables of each data point."));231 Parameters.Add(new OptionalConstrainedValueParameter<StringValue>(ClassesNameParameterName, "Name of the column specifying the class lables of each data point.")); 232 232 Parameters.Add(new FixedValueParameter<BoolValue>(NormalizationParameterName, "Whether the data should be zero centered and have variance of 1 for each variable, so different scalings are ignored.", new BoolValue(true))); 233 233 Parameters.Add(new FixedValueParameter<IntValue>(UpdateIntervalParameterName, "", new IntValue(50))); … … 273 273 if (Normalization) data = NormalizeData(data); 274 274 275 state = TSNEStatic<double[]>.CreateState(data, Distance , random, NewDimensions, Perplexity, Theta,275 state = TSNEStatic<double[]>.CreateState(data, DistanceFunction, random, NewDimensions, Perplexity, Theta, 276 276 StopLyingIteration, MomentumSwitchIteration, InitialMomentum, FinalMomentum, Eta); 277 277 … … 305 305 private void OnProblemDataChanged(object sender, EventArgs args) { 306 306 if (Problem == null || Problem.ProblemData == null) return; 307 if (!Parameters.ContainsKey(Classes ParameterName)) return;308 Classes Parameter.ValidValues.Clear();309 foreach (var input in Problem.ProblemData.InputVariables) Classes Parameter.ValidValues.Add(input);307 if (!Parameters.ContainsKey(ClassesNameParameterName)) return; 308 ClassesNameParameter.ValidValues.Clear(); 309 foreach (var input in Problem.ProblemData.InputVariables) ClassesNameParameter.ValidValues.Add(input); 310 310 } 311 311 … … 321 321 322 322 //color datapoints acording to classes variable (be it double or string) 323 if (problemData.Dataset.VariableNames.Contains(Classes )) {324 if ((problemData.Dataset as Dataset).VariableHasType<string>(Classes )) {325 var classes = problemData.Dataset.GetStringValues(Classes ).ToArray();323 if (problemData.Dataset.VariableNames.Contains(ClassesName)) { 324 if ((problemData.Dataset as Dataset).VariableHasType<string>(ClassesName)) { 325 var classes = problemData.Dataset.GetStringValues(ClassesName).ToArray(); 326 326 for (var i = 0; i < classes.Length; i++) { 327 327 if (!dataRowNames.ContainsKey(classes[i])) dataRowNames.Add(classes[i], new List<int>()); 328 328 dataRowNames[classes[i]].Add(i); 329 329 } 330 } else if ((problemData.Dataset as Dataset).VariableHasType<double>(Classes )) {331 var classValues = problemData.Dataset.GetDoubleValues(Classes ).ToArray();330 } else if ((problemData.Dataset as Dataset).VariableHasType<double>(ClassesName)) { 331 var classValues = problemData.Dataset.GetDoubleValues(ClassesName).ToArray(); 332 332 var max = classValues.Max() + 0.1; 333 333 var min = classValues.Min() - 0.1;
Note: See TracChangeset
for help on using the changeset viewer.