Exemplo n.º 1
0
        private void btLoadModel_Click(object sender, EventArgs e)
        {
            try {
                Cursor.Current = Cursors.WaitCursor;
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(DBNmodel));
                XmlReader xmlReader = XmlReader.Create(settings.ModelFilename);

                model = (DBNmodel)xmlSerializer.Deserialize(xmlReader);
            } catch {
                model = null;
            } finally {
                Cursor.Current = Cursors.Arrow;
            }

            if (model == null || model.layers.Length == 0) {
                MessageBox.Show("Invalid model.");
                return;
            }

            RBMlayer bottomLayer = model.layers[0];

            int visibleUnits = bottomLayer.I;

            minWeight = maxWeight = bottomLayer.weights[0];
            maxWeightBias = 0.0f;

            for (int j = 0; j < bottomLayer.J; j++) {
                float bias = bottomLayer.biasHiddenLayer[j];

                for (int i = 0; i < visibleUnits; i++) {
                    float w = bottomLayer.Weight(j, i);

                    if (minWeight > w) {
                        minWeight = w;
                    } else if (maxWeight < w) {
                        maxWeight = w;
                    }

                    if (bias + w > maxWeightBias) maxWeightBias = bias + w;
                }
            }

            if (settings.Width == 0 && settings.Height == 0) {
                int pixels = (int)Math.Sqrt(visibleUnits);
                if (visibleUnits == pixels * pixels) {
                    settings.Width = settings.Height = pixels;
                    proprieties.SelectedObject = settings;
                }
            }

            dstrain = new DataSet(model.TrainFilename, Path.GetDirectoryName(settings.ModelFilename));
            imageScroll.Maximum = dstrain.Samples - 1;

            splitContainer.Panel2.Invalidate();
        }
Exemplo n.º 2
0
        private void btLoadModel_Click(object sender, EventArgs e)
        {
            try {
                Cursor.Current = Cursors.WaitCursor;
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(DBNmodel));
                XmlReader     xmlReader     = XmlReader.Create(settings.ModelFilename);

                model = (DBNmodel)xmlSerializer.Deserialize(xmlReader);
            } catch {
                model = null;
            } finally {
                Cursor.Current = Cursors.Arrow;
            }

            if (model == null || model.layers.Length == 0)
            {
                MessageBox.Show("Invalid model.");
                return;
            }

            RBMlayer bottomLayer = model.layers[0];

            int visibleUnits = bottomLayer.I;

            minWeight     = maxWeight = bottomLayer.weights[0];
            maxWeightBias = 0.0f;

            for (int j = 0; j < bottomLayer.J; j++)
            {
                float bias = bottomLayer.biasHiddenLayer[j];

                for (int i = 0; i < visibleUnits; i++)
                {
                    float w = bottomLayer.Weight(j, i);

                    if (minWeight > w)
                    {
                        minWeight = w;
                    }
                    else if (maxWeight < w)
                    {
                        maxWeight = w;
                    }

                    if (bias + w > maxWeightBias)
                    {
                        maxWeightBias = bias + w;
                    }
                }
            }

            if (settings.Width == 0 && settings.Height == 0)
            {
                int pixels = (int)Math.Sqrt(visibleUnits);
                if (visibleUnits == pixels * pixels)
                {
                    settings.Width             = settings.Height = pixels;
                    proprieties.SelectedObject = settings;
                }
            }

            dstrain             = new DataSet(model.TrainFilename, Path.GetDirectoryName(settings.ModelFilename));
            imageScroll.Maximum = dstrain.Samples - 1;

            splitContainer.Panel2.Invalidate();
        }