Changeset 14518
- Timestamp:
- 12/22/16 10:08:25 (8 years ago)
- Location:
- branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs
r14185 r14518 44 44 [StorableClass] 45 45 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 350)] 46 public class GradientBoostingRegressionAlgorithm : BasicAlgorithm {46 public class GradientBoostingRegressionAlgorithm : BasicAlgorithm, IDataAnalysisAlgorithm<IRegressionProblem> { 47 47 public override Type ProblemType { 48 48 get { return typeof(IRegressionProblem); } -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegression.cs
r14185 r14518 39 39 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 160)] 40 40 [StorableClass] 41 public sealed class GaussianProcessRegression : GaussianProcessBase, IStorableContent {41 public sealed class GaussianProcessRegression : GaussianProcessBase, IStorableContent, IDataAnalysisAlgorithm<IRegressionProblem> { 42 42 public string Filename { get; set; } 43 43 -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
r14345 r14518 38 38 [StorableClass] 39 39 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 125)] 40 public class GradientBoostedTreesAlgorithm : BasicAlgorithm { 41 public override Type ProblemType { 40 public class GradientBoostedTreesAlgorithm : BasicAlgorithm, IDataAnalysisAlgorithm<IRegressionProblem> { 41 public override Type ProblemType 42 { 42 43 get { return typeof(IRegressionProblem); } 43 44 } 44 public new IRegressionProblem Problem { 45 public new IRegressionProblem Problem 46 { 45 47 get { return (IRegressionProblem)base.Problem; } 46 48 set { base.Problem = value; } … … 61 63 62 64 #region ParameterProperties 63 public IFixedValueParameter<IntValue> IterationsParameter { 65 public IFixedValueParameter<IntValue> IterationsParameter 66 { 64 67 get { return (IFixedValueParameter<IntValue>)Parameters[IterationsParameterName]; } 65 68 } 66 public IFixedValueParameter<IntValue> MaxSizeParameter { 69 public IFixedValueParameter<IntValue> MaxSizeParameter 70 { 67 71 get { return (IFixedValueParameter<IntValue>)Parameters[MaxSizeParameterName]; } 68 72 } 69 public IFixedValueParameter<DoubleValue> NuParameter { 73 public IFixedValueParameter<DoubleValue> NuParameter 74 { 70 75 get { return (IFixedValueParameter<DoubleValue>)Parameters[NuParameterName]; } 71 76 } 72 public IFixedValueParameter<DoubleValue> RParameter { 77 public IFixedValueParameter<DoubleValue> RParameter 78 { 73 79 get { return (IFixedValueParameter<DoubleValue>)Parameters[RParameterName]; } 74 80 } 75 public IFixedValueParameter<DoubleValue> MParameter { 81 public IFixedValueParameter<DoubleValue> MParameter 82 { 76 83 get { return (IFixedValueParameter<DoubleValue>)Parameters[MParameterName]; } 77 84 } 78 public IFixedValueParameter<IntValue> SeedParameter { 85 public IFixedValueParameter<IntValue> SeedParameter 86 { 79 87 get { return (IFixedValueParameter<IntValue>)Parameters[SeedParameterName]; } 80 88 } 81 public FixedValueParameter<BoolValue> SetSeedRandomlyParameter { 89 public FixedValueParameter<BoolValue> SetSeedRandomlyParameter 90 { 82 91 get { return (FixedValueParameter<BoolValue>)Parameters[SetSeedRandomlyParameterName]; } 83 92 } 84 public IConstrainedValueParameter<ILossFunction> LossFunctionParameter { 93 public IConstrainedValueParameter<ILossFunction> LossFunctionParameter 94 { 85 95 get { return (IConstrainedValueParameter<ILossFunction>)Parameters[LossFunctionParameterName]; } 86 96 } 87 public IFixedValueParameter<IntValue> UpdateIntervalParameter { 97 public IFixedValueParameter<IntValue> UpdateIntervalParameter 98 { 88 99 get { return (IFixedValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; } 89 100 } 90 public IFixedValueParameter<BoolValue> CreateSolutionParameter { 101 public IFixedValueParameter<BoolValue> CreateSolutionParameter 102 { 91 103 get { return (IFixedValueParameter<BoolValue>)Parameters[CreateSolutionParameterName]; } 92 104 } … … 94 106 95 107 #region Properties 96 public int Iterations { 108 public int Iterations 109 { 97 110 get { return IterationsParameter.Value.Value; } 98 111 set { IterationsParameter.Value.Value = value; } 99 112 } 100 public int Seed { 113 public int Seed 114 { 101 115 get { return SeedParameter.Value.Value; } 102 116 set { SeedParameter.Value.Value = value; } 103 117 } 104 public bool SetSeedRandomly { 118 public bool SetSeedRandomly 119 { 105 120 get { return SetSeedRandomlyParameter.Value.Value; } 106 121 set { SetSeedRandomlyParameter.Value.Value = value; } 107 122 } 108 public int MaxSize { 123 public int MaxSize 124 { 109 125 get { return MaxSizeParameter.Value.Value; } 110 126 set { MaxSizeParameter.Value.Value = value; } 111 127 } 112 public double Nu { 128 public double Nu 129 { 113 130 get { return NuParameter.Value.Value; } 114 131 set { NuParameter.Value.Value = value; } 115 132 } 116 public double R { 133 public double R 134 { 117 135 get { return RParameter.Value.Value; } 118 136 set { RParameter.Value.Value = value; } 119 137 } 120 public double M { 138 public double M 139 { 121 140 get { return MParameter.Value.Value; } 122 141 set { MParameter.Value.Value = value; } 123 142 } 124 public bool CreateSolution { 143 public bool CreateSolution 144 { 125 145 get { return CreateSolutionParameter.Value.Value; } 126 146 set { CreateSolutionParameter.Value.Value = value; } … … 129 149 130 150 #region ResultsProperties 131 private double ResultsBestQuality { 151 private double ResultsBestQuality 152 { 132 153 get { return ((DoubleValue)Results["Best Quality"].Value).Value; } 133 154 set { ((DoubleValue)Results["Best Quality"].Value).Value = value; } 134 155 } 135 private DataTable ResultsQualities { 156 private DataTable ResultsQualities 157 { 136 158 get { return ((DataTable)Results["Qualities"].Value); } 137 159 } -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj
r14512 r14518 338 338 <SubType>Code</SubType> 339 339 </Compile> 340 <Compile Include="KPCA\SelfOrganizingMap.cs" />341 <Compile Include="KPCA\KernelFunctions\CicularKernel.cs" />342 <Compile Include="KPCA\KernelFunctions\GaussianKernel.cs" />343 <Compile Include="KPCA\KernelFunctions\InverseMultiquadraticKernel .cs" />344 <Compile Include="KPCA\KernelFunctions\LaplacianKernel.cs" />345 <Compile Include="KPCA\KernelFunctions\MultiquadraticKernel.cs" />346 <Compile Include="KPCA\KernelFunctions\NoKernel.cs" />347 <Compile Include="KPCA\KernelFunctions\PolysplineKernel.cs" />348 <Compile Include="KPCA\KernelFunctions\RadialBasisKernelBase.cs" />349 <Compile Include="KPCA\KernelFunctions\ThinPlatePolysplineKernel.cs" />350 <Compile Include="KPCA\KernelFunctions\TricubicKernel.cs" />351 <Compile Include="KPCA\KernelPrincipleComponentAnalysis.cs" />352 <Compile Include="KPCA\Isomap.cs" />353 <Compile Include="KPCA\KPCA.cs" />354 <Compile Include="KPCA\MatrixUtilities.cs" />355 340 <Compile Include="Linear\AlglibUtil.cs" /> 356 341 <Compile Include="Linear\Scaling.cs" /> -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/Cell.cs
r14414 r14518 57 57 using System.Linq; 58 58 using HeuristicLab.Common; 59 using HeuristicLab.Core;60 59 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 61 60 62 61 namespace HeuristicLab.Algorithms.DataAnalysis { 63 62 [StorableClass] 64 public class Cell : Item, ICell {63 public class Cell : DeepCloneable, ICell { 65 64 #region properties 66 65 [Storable] … … 74 73 #region HLConstructors & Cloning 75 74 [StorableConstructor] 76 protected Cell(bool deserializing) : base(deserializing){ }75 protected Cell(bool deserializing) { } 77 76 protected Cell(Cell original, Cloner cloner) : base(original, cloner) { 78 77 dimension = original.dimension; … … 112 111 return true; 113 112 } 114 115 116 113 } 117 114 } -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/DataPoint.cs
r14414 r14518 55 55 56 56 using HeuristicLab.Common; 57 using HeuristicLab.Core;58 57 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 59 58 60 59 namespace HeuristicLab.Algorithms.DataAnalysis { 61 60 [StorableClass] 62 public class DataPoint<T> : Item, IDataPoint<T> where T : class, IDeepCloneable {61 public class DataPoint<T> : DeepCloneable, IDataPoint<T> where T : class, IDeepCloneable { 63 62 #region properties 64 63 [Storable] … … 75 74 #region HLConstructors & Cloning 76 75 [StorableConstructor] 77 protected DataPoint(bool deserializing) : base(deserializing){ }76 protected DataPoint(bool deserializing) { } 78 77 protected DataPoint(DataPoint<T> original, Cloner cloner) 79 78 : base(original, cloner) { -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/SPtree.cs
r14414 r14518 58 58 using System.Linq; 59 59 using HeuristicLab.Common; 60 using HeuristicLab.Core;61 60 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 62 61 63 62 namespace HeuristicLab.Algorithms.DataAnalysis { 64 63 [StorableClass] 65 public class SPTree : Item, ISPTree {64 public class SPTree : DeepCloneable, ISPTree { 66 65 private const uint QT_NODE_CAPACITY = 1; 67 66 … … 100 99 #region HLConstructors & Cloning 101 100 [StorableConstructor] 102 protected SPTree(bool deserializing) : base(deserializing){ }101 protected SPTree(bool deserializing) { } 103 102 protected SPTree(SPTree original, Cloner cloner) 104 103 : base(original, cloner) { -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/TSNE.cs
r14512 r14518 67 67 namespace HeuristicLab.Algorithms.DataAnalysis { 68 68 [StorableClass] 69 public class TSNE<T> : Item, ITSNE<T> where T : class, IDeepCloneable {69 public class TSNE<T> : DeepCloneable, ITSNE<T> where T : class, IDeepCloneable { 70 70 71 71 private const string IterationResultName = "Iteration"; … … 106 106 #region HLConstructors & Cloning 107 107 [StorableConstructor] 108 protected TSNE(bool deserializing) : base(deserializing){ }108 protected TSNE(bool deserializing) { } 109 109 protected TSNE(TSNE<T> original, Cloner cloner) : base(original, cloner) { 110 110 distance = cloner.Clone(original.distance); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/TSNEAnalysis.cs
r14512 r14518 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Drawing; 24 25 using System.Linq; 26 using System.Threading; 25 27 using HeuristicLab.Analysis; 26 28 using HeuristicLab.Common; … … 28 30 using HeuristicLab.Data; 29 31 using HeuristicLab.Encodings.RealVectorEncoding; 32 using HeuristicLab.Optimization; 30 33 using HeuristicLab.Parameters; 31 34 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 40 43 [Creatable(CreatableAttribute.Categories.DataAnalysis, Priority = 100)] 41 44 [StorableClass] 42 public sealed class TSNEAnalysis : FixedDataAnalysisAlgorithm<IRegressionProblem> { 43 45 public sealed class TSNEAnalysis : BasicAlgorithm { 46 47 public override Type ProblemType 48 { 49 get { return typeof(IDataAnalysisProblem); } 50 } 51 public new IDataAnalysisProblem Problem 52 { 53 get { return (IDataAnalysisProblem)base.Problem; } 54 set { base.Problem = value; } 55 } 44 56 #region Resultnames 45 57 private const string ScatterPlotResultName = "Scatterplot"; … … 61 73 private const string SeedParameterName = "Seed"; 62 74 private const string ClassesParameterName = "ClassNames"; 75 private const string NormalizationParameterName = "Normalization"; 63 76 #endregion 64 77 … … 115 128 { 116 129 get { return Parameters[ClassesParameterName] as IFixedValueParameter<StringValue>; } 130 } 131 public IFixedValueParameter<BoolValue> NormalizationParameter 132 { 133 get { return Parameters[NormalizationParameterName] as IFixedValueParameter<BoolValue>; } 117 134 } 118 135 #endregion … … 174 191 get { return ClassesParameter.Value.Value; } 175 192 } 176 193 public bool Normalization 194 { 195 get { return NormalizationParameter.Value.Value; } 196 } 177 197 [Storable] 178 198 public TSNE<RealVector> tsne; … … 191 211 Parameters.Add(new FixedValueParameter<IntValue>(NewDimensionsParameterName, "Dimensionality of projected space (usually 2 for easy visual analysis", new IntValue(2))); 192 212 Parameters.Add(new FixedValueParameter<IntValue>(MaxIterationsParameterName, "Maximum number of iterations for gradient descent", new IntValue(1000))); 193 Parameters.Add(new FixedValueParameter<IntValue>(StopLyingIterationParameterName, "Number of iterations after which p is no longer approximated", new IntValue( 250)));194 Parameters.Add(new FixedValueParameter<IntValue>(MomentumSwitchIterationParameterName, "Number of iterations after which the momentum in the gradient descent is switched", new IntValue( 250)));213 Parameters.Add(new FixedValueParameter<IntValue>(StopLyingIterationParameterName, "Number of iterations after which p is no longer approximated", new IntValue(0))); 214 Parameters.Add(new FixedValueParameter<IntValue>(MomentumSwitchIterationParameterName, "Number of iterations after which the momentum in the gradient descent is switched", new IntValue(0))); 195 215 Parameters.Add(new FixedValueParameter<DoubleValue>(InitialMomentumParameterName, "The initial momentum in the gradient descent", new DoubleValue(0.5))); 196 216 Parameters.Add(new FixedValueParameter<DoubleValue>(FinalMomentumParameterName, "The final momentum", new DoubleValue(0.8))); … … 199 219 Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The seed used if it should not be random", new IntValue(0))); 200 220 Parameters.Add(new FixedValueParameter<StringValue>(ClassesParameterName, "name of the column specifying the class lables of each data point. \n if the lable column can not be found Training/Test is used as labels", new StringValue("none"))); 201 } 202 #endregion 203 204 protected override void Run() { 205 var data = CalculateProjectedData(Problem.ProblemData); 206 var lowDimData = new DoubleMatrix(data); 207 } 221 Parameters.Add(new FixedValueParameter<BoolValue>(NormalizationParameterName, "Wether the data should be zero centered and have variance of 1 for each variable, so different scalings are ignored", new BoolValue(true))); 222 223 MomentumSwitchIterationParameter.Hidden = true; 224 InitialMomentumParameter.Hidden = true; 225 FinalMomentumParameter.Hidden = true; 226 StopLyingIterationParameter.Hidden = true; 227 EtaParameter.Hidden = true; 228 } 229 #endregion 208 230 209 231 public override void Stop() { … … 212 234 } 213 235 236 protected override void Run(CancellationToken cancellationToken) { 237 var data = CalculateProjectedData(Problem.ProblemData); 238 var lowDimData = new DoubleMatrix(data); 239 } 240 214 241 private double[,] CalculateProjectedData(IDataAnalysisProblemData problemData) { 215 var DataRowNames = new Dictionary<string, List<int>>();242 var dataRowNames = new Dictionary<string, List<int>>(); 216 243 var rows = new Dictionary<string, ScatterPlotDataRow>(); 217 244 … … 220 247 var classes = problemData.Dataset.GetStringValues(Classes).ToArray(); 221 248 for (int i = 0; i < classes.Length; i++) { 222 if (! DataRowNames.ContainsKey(classes[i])) DataRowNames.Add(classes[i], new List<int>());223 DataRowNames[classes[i]].Add(i); //always succeeds249 if (!dataRowNames.ContainsKey(classes[i])) dataRowNames.Add(classes[i], new List<int>()); 250 dataRowNames[classes[i]].Add(i); //always succeeds 224 251 } 225 252 } else if ((problemData.Dataset as Dataset).VariableHasType<double>(Classes)) { … … 228 255 var min = classValues.Min() - 0.1; 229 256 var contours = 8; 230 for ( inti = 0; i < contours; i++) {257 for (var i = 0; i < contours; i++) { 231 258 var name = GetContourName(i, min, max, contours); 232 DataRowNames.Add(name, new List<int>());259 dataRowNames.Add(name, new List<int>()); 233 260 rows.Add(name, new ScatterPlotDataRow(name, "", new List<Point2D<double>>())); 234 261 rows[name].VisualProperties.Color = GetHeatMapColor(i, contours); 235 rows[name].VisualProperties.PointSize = i +3;262 rows[name].VisualProperties.PointSize = i + 3; 236 263 } 237 264 for (int i = 0; i < classValues.Length; i++) { 238 DataRowNames[GetContourName(classValues[i], min, max, contours)].Add(i); //always succeeds265 dataRowNames[GetContourName(classValues[i], min, max, contours)].Add(i); //always succeeds 239 266 } 240 267 241 268 } 242 269 243 244 270 } else { 245 DataRowNames.Add("Training", problemData.TrainingIndices.ToList());246 DataRowNames.Add("Test", problemData.TestIndices.ToList());271 dataRowNames.Add("Training", problemData.TrainingIndices.ToList()); 272 dataRowNames.Add("Test", problemData.TestIndices.ToList()); 247 273 } 248 274 249 275 var random = SetSeedRandomly ? new MersenneTwister() : new MersenneTwister(Seed); 250 tsne = new TSNE<RealVector>(Distance, random, Results, MaxIterations, StopLyingIteration, MomentumSwitchIteration, InitialMomentum, FinalMomentum, Eta, DataRowNames, rows);276 tsne = new TSNE<RealVector>(Distance, random, Results, MaxIterations, StopLyingIteration, MomentumSwitchIteration, InitialMomentum, FinalMomentum, Eta, dataRowNames, rows); 251 277 var dataset = problemData.Dataset; 252 278 var allowedInputVariables = problemData.AllowedInputVariables.ToArray(); 253 279 var data = new RealVector[dataset.Rows]; 254 280 for (var row = 0; row < dataset.Rows; row++) data[row] = new RealVector(allowedInputVariables.Select(col => dataset.GetDoubleValue(col, row)).ToArray()); 281 282 if (Normalization) { 283 data = NormalizeData(data); 284 } 285 255 286 return tsne.Run(data, NewDimensions, Perplexity, Theta); 287 } 288 289 private RealVector[] NormalizeData(RealVector[] data) { 290 var n = data[0].Length; 291 var mean = new double[n]; 292 var sd = new double[n]; 293 var nData = new RealVector[data.Length]; 294 for (var i = 0; i < n; i++) { 295 var i1 = i; 296 sd[i] = Enumerable.Range(0, data.Length).Select(x => data[x][i1]).StandardDeviation(); 297 mean[i] = Enumerable.Range(0, data.Length).Select(x => data[x][i1]).Average(); 298 } 299 for (int i = 0; i < data.Length; i++) { 300 nData[i] = new RealVector(n); 301 for (int j = 0; j < n; j++) { 302 nData[i][j] = (data[i][j] - mean[j]) / sd[j]; 303 } 304 } 305 return nData; 306 307 256 308 } 257 309 -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/VPTree.cs
r14414 r14518 64 64 namespace HeuristicLab.Algorithms.DataAnalysis { 65 65 [StorableClass] 66 public class VPTree<T> : Item, IVPTree<T> where T : class, IDeepCloneable {66 public class VPTree<T> : DeepCloneable, IVPTree<T> where T : class, IDeepCloneable { 67 67 #region properties 68 68 [Storable] … … 78 78 #region HLConstructors & Cloning 79 79 [StorableConstructor] 80 protected VPTree(bool deserializing) : base(deserializing){ }80 protected VPTree(bool deserializing) { } 81 81 protected VPTree(VPTree<T> original, Cloner cloner) 82 82 : base(original, cloner) {
Note: See TracChangeset
for help on using the changeset viewer.