Ejemplo n.º 1
0
        public SelfOrganizingMap(PointSet data, List <int> dimensions, int totalItt, double learningRate)
        {
            //Get initial learning rate
            this.initialLearningRate = learningRate;
            this.learningRate        = learningRate;
            influence             = 0;
            this.totalItterations = totalItt;
            itterations           = 1;

            this.dimensions = dimensions;
            this.data       = data;
            rng             = new Random((int)DateTime.Now.Ticks);

            int numNeurons = 1;

            foreach (int d in dimensions)
            {
                numNeurons *= d;
            }

            int[] pos = new int[dimensions.Count];
            for (int i = 0; i < dimensions.Count; i++)
            {
                pos[i] = 0;
            }

            //Scale each attribute from [0,1] and store the conversion matrix
            conversionMatrix = data.GetMinMaxWeights().Max.Coordinates;

            foreach (KPoint d in data.PointList)
            {
                d.Normalize(conversionMatrix);
            }

            //Here We will initialize Our Neurons
            neurons = new List <SOMNeuron>();
            KPoint zero = KPoint.Zero(data[0].Dimensions);
            KPoint one  = KPoint.One(data[0].Dimensions);

            for (int i = 0; i < numNeurons; i++)
            {
                //Generate our neurons
                double[] posNeuron = new double[dimensions.Count];
                for (int d = 0; d < dimensions.Count; d++)
                {
                    posNeuron[d] = (double)pos[d];
                }
                SOMNeuron neuron = new SOMNeuron(zero, one, rng, new KPoint(posNeuron), i);
                neurons.Add(neuron);
                addOneCarry(ref pos, dimensions);
            }

            //Get the max radius
            setRadius();

            this.timeConstant = (double)totalItterations / Math.Log(radius);
        }
        public HexagonalSelfOrganizingMap(PointSet data, int dimension, double learningRate)
        {
            _dimension = dimension;

            //Get initial learning rate
            this.initialLearningRate = learningRate;
            this.learningRate        = learningRate;
            influence   = 0;
            itterations = 1;

            this.data = data;
            rng       = new Random();

            int numNeurons = dimension * dimension;

            //Scale each attribute from [0,1] and store the conversion matrix
            conversionMatrix = data.GetMinMaxWeights().Max.Coordinates;

            foreach (KPoint d in data.PointList)
            {
                d.Normalize(conversionMatrix);
            }

            //Here We will initialize Our Neurons
            neurons = new List <SOMNeuron>();
            KPoint zero            = KPoint.Zero(data[0].Dimensions);
            KPoint one             = KPoint.One(data[0].Dimensions);
            double halfNeuronDelta = 1 / Math.Sqrt(3.0);

            //Initialize our Quadtree for reference
            double centerX             = (dimension - 0.5) * (2 * halfNeuronDelta) / 2.0;
            double centerY             = (dimension - 1.0) / 2.0;
            QuadTreePointStruct center = new QuadTreePointStruct()
            {
                Index = -1, X = centerX, Y = centerY
            };
            QuadTreePointStruct halfDistance = new QuadTreePointStruct()
            {
                Index = -1, X = centerX + halfNeuronDelta, Y = centerY + 0.5
            };

            neuronQuadTree = new QuadTree(new QuadTreeBoundingBox()
            {
                Center = center, HalfLength = halfDistance
            });

            int neuronIndex = 0;

            for (int r = 0; r < dimension; r++)
            {
                double xPos = (r % 2 == 1) ? halfNeuronDelta : 0.0;
                for (int c = 0; c < dimension; c++)
                {
                    //Generate our neurons
                    double[]            posNeuron   = { xPos, (double)r };
                    SOMNeuron           neuron      = new SOMNeuron(zero, one, rng, new KPoint(posNeuron), neuronIndex);
                    QuadTreePointStruct neuronQTPos = new QuadTreePointStruct()
                    {
                        Index = neuronIndex,
                        X     = posNeuron[0],
                        Y     = posNeuron[1]
                    };
                    neuronQuadTree.Insert(neuronQTPos);
                    neurons.Add(neuron);
                    xPos += 2 * halfNeuronDelta;
                    neuronIndex++;
                }
            }



            //Get the max radius
            SetRadius();

            timeConstant = (double)totalItterations / Math.Log(radius);
        }