Пример #1
0
        public INoise GetLandFormFct()
        {
            //REM
            //The various parameters value here are scaled for a gradient being feed by 0 to 1 input value.
            //When this gradient is configured to recevied other value range then some parameters needs to be rescaled
            //That's the reason for using this _groundGradientTyped.AdjustY value
            //This way no matter the the Gradient Range, the values impacting it will be rescaled.

            //Create the Lowland base fractal with range from 0 to 1 values
            INoise montain_shape_fractal = new FractalFbm(new Simplex(_seed), 4, 3.5, enuBaseNoiseRange.ZeroToOne);
            INoise montain_shape_Ajusted = new ScaleOffset(montain_shape_fractal, 0.9, -0.02);

            //Rescale + offset the output result ==> Wil modify the Scope of output range value
            //Enforce gradient to have a solid underground
            INoise _groundGradientAjusted = new Bias(_groundGradient, 0.55);
            INoise adjustedGradient       = new ScaleOffset(_groundGradientAjusted, 1.4, 0);

            Combiner noiseCombiner = new Combiner(Combiner.CombinerType.Add);

            noiseCombiner.Noises.Add(montain_shape_Ajusted);
            noiseCombiner.Noises.Add(adjustedGradient);

            INoise rescaledCombinedNoise = new ScaleOffset(noiseCombiner, 0.45, 0);

            return(rescaledCombinedNoise);
        }
Пример #2
0
        public INoise GetLandFormFct()
        {
            //REM
            //The various parameters value here are scaled for a gradient being feed by 0 to 1 input value.
            //When this gradient is configured to recevied other value range then some parameters needs to be rescaled
            //That's the reason for using this _groundGradientTyped.AdjustY value
            //This way no matter the the Gradient Range, the values impacting it will be rescaled.

            //Create the Lowland base fractal with range from 0 to 1 values
            INoise river_shape_fractal = new FractalRidgedMulti(new Simplex(_seed), 1, 2, enuBaseNoiseRange.ZeroToOne);
            //Rescale + offset the output result ==> Wil modify the Scope of output range value
            INoise river_shape_scale = new ScaleOffset(river_shape_fractal, 0.30, 0.01);
            //Remove Y value from impacting the result (Fixed to 0), the value output range will not be changed, but the influence of the Y will be removed

            //Force the Fractal to be used as 2D Noise, I don't need to 3th dimension
            INoise river_y_scale = new NoiseAccess(river_shape_fractal, NoiseAccess.enuDimUsage.Noise2D, true);

            INoise turb           = new ScaleOffset(river_y_scale, 0.03, 0);
            INoise river_selected = new Select(0, turb, river_y_scale, 0.7);  //Last param define the width of the river

            //Offset the ground_gradient ( = create turbulance) to the Y scale of the gradient. input value
            INoise _groundGradient_biased = new Bias(_groundGradient, 0.45);
            INoise river = new Turbulence(_groundGradient_biased, 0, river_selected);

            return(river);
        }
Пример #3
0
        public void Save(Stream s)
        {
            XmlWriter w = null;

            try
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent           = true;
                settings.ConformanceLevel = ConformanceLevel.Fragment;
                w = XmlWriter.Create(s, settings);
                w.WriteStartElement("ColorMap");
                w.WriteAttributeString("Type", Type.ToString());
                w.WriteAttributeString("Bias", Bias.ToString());
                w.WriteAttributeString("Contrast", Contrast.ToString());
                SaveCore(w);
                w.WriteEndElement();
            }
            finally
            {
                if (w != null)
                {
                    w.Close();
                }
            }
        }
Пример #4
0
        public override bool ViewToModel(Point position, out int offset, out Bias bias)
        {
            if (LayoutInvalid)
            {
                offset = -1;
                bias   = Bias.Forward;
                return(false);
            }

            if (!LayoutRect.Contains(position))
            {
                offset = -1;
                bias   = Bias.Forward;
                return(false);
            }

            var targetWidth = position.X - LayoutRect.X;

            offset = FindEditPositionBreakOffset(targetWidth);
            if (offset == EndOffset)
            {
                bias = Bias.Backward;
                return(true);
            }

            var offsetWidth = WidthFor(Offset, offset);
            var nextWidth   = WidthFor(Offset, offset + 1);
            var width       = nextWidth - offsetWidth;

            bias = targetWidth - offsetWidth < width / 2 ? Bias.Backward : Bias.Forward;
            return(true);
        }
Пример #5
0
        private void Forward(TensorOld input, int sampleIndex, int filterIndex)
        {
            Parallel.For(0, outRows, row =>
            {
                var startRow = row * RowStride;
                Parallel.For(0, outColumns, col =>
                {
                    var startCol = col * ColumnStride;
                    var sum      = 0d;

                    for (int i = 0; i < FilterRows; i++)
                    {
                        var inputRow = startRow + i;
                        for (int j = 0; j < FilterColumns; j++)
                        {
                            var inputCol = startCol + j;

                            for (int k = 0; k < channels; k++)
                            {
                                sum += PaddingInput[sampleIndex, k, inputRow, inputCol] * Filters[filterIndex, k, i, j];
                            }
                        }
                    }
                    ForwardOutput[sampleIndex, filterIndex, row, col] = sum + Bias.GetRawValues()[filterIndex];
                });
            });
        }
Пример #6
0
 /// <summary>
 /// Initialize a new <see cref="WordChecker"/> with the specified <paramref name="bias"/>, <paramref name="headCheck"/>, <paramref name="bodyCheck"/>, and <paramref name="tailCheck"/>.
 /// </summary>
 /// <param name="bias">Whether the word is head or tail biased.</param>
 /// <param name="headCheck">A <see cref="Func{T, TResult}"/> taking a <see cref="Char"/> and returning a <see cref="Boolean"/></param>
 /// <param name="bodyCheck">A <see cref="Func{T, TResult}"/> taking a <see cref="Char"/> and returning a <see cref="Boolean"/></param>
 /// <param name="tailCheck">A <see cref="Func{T, TResult}"/> taking a <see cref="Char"/> and returning a <see cref="Boolean"/></param>
 internal WordChecker(Bias bias, Func <Char, Boolean> headCheck, Func <Char, Boolean> bodyCheck, Func <Char, Boolean> tailCheck)
 {
     Bias      = bias;
     HeadCheck = headCheck;
     BodyCheck = bodyCheck;
     TailCheck = tailCheck;
 }
Пример #7
0
 /// <summary>
 /// Use the specified <paramref name="headCheck"/>, <paramref name="bodyCheck"/>, and <paramref name="tailCheck"/> to represent the valid form of a word, along with the <paramref name="bias"/>.
 /// </summary>
 /// <param name="name">Name to display this pattern as.</param>
 /// <param name="bias">Endian bias of the word. Head bias requires the head if only one letter is present. Tail bias requires the tail if only one letter is present.</param>
 /// <param name="headCheck">A <see cref="Func{T, TResult}"/> to validate the head.</param>
 /// <param name="bodyCheck">A <see cref="Func{T, TResult}"/> to validate the body, which may repeat.</param>
 /// <param name="tailCheck">A <see cref="Func{T, TResult}"/> to validate the tail.</param>
 /// <returns></returns>
 public static Pattern Check(Bias bias, Func <Char, Boolean> headCheck, Func <Char, Boolean> bodyCheck, Func <Char, Boolean> tailCheck)
 {
     Guard.NotNull(headCheck, nameof(headCheck));
     Guard.NotNull(bodyCheck, nameof(bodyCheck));
     Guard.NotNull(tailCheck, nameof(tailCheck));
     return(new WordChecker(bias, headCheck, bodyCheck, tailCheck));
 }
Пример #8
0
 /// <summary>
 /// Initialize a new <see cref="WordChecker"/> with the specified <paramref name="name"/>, <paramref name="bias"/>, <paramref name="headCheck"/>, <paramref name="bodyCheck"/>, and <paramref name="tailCheck"/>.
 /// </summary>
 /// <param name="name">The name to refer to this as</param>
 /// <param name="bias">Whether the word is head or tail biased.</param>
 /// <param name="headCheck">A <see cref="Func{T, TResult}"/> taking a <see cref="Char"/> and returning a <see cref="Boolean"/></param>
 /// <param name="bodyCheck">A <see cref="Func{T, TResult}"/> taking a <see cref="Char"/> and returning a <see cref="Boolean"/></param>
 /// <param name="tailCheck">A <see cref="Func{T, TResult}"/> taking a <see cref="Char"/> and returning a <see cref="Boolean"/></param>
 internal WordChecker(String name, Bias bias, Func <Char, Boolean> headCheck, Func <Char, Boolean> bodyCheck, Func <Char, Boolean> tailCheck) : base(name)
 {
     Bias      = bias;
     HeadCheck = headCheck;
     BodyCheck = bodyCheck;
     TailCheck = tailCheck;
 }
Пример #9
0
        /// <summary>
        /// 通过I2C获取温度,Vcc,Bias,TxPower
        /// </summary>
        void GetParas()
        {
            //AOH 读取SN
            //A2H
            double      temp, vcc, txPower, bais;
            short       cache  = 0;
            ushort      ucache = 0;
            List <byte> data   = TranBase.MyI2C_ReadA2HByte(SerBuf, Port, 96, 10);

            //Temp 96,97
            cache            = DigitTransform(data[0], data[1]);
            temp             = (double)cache / 256;
            Temp             = temp;
            TestingPara.Temp = Temp.ToString();
            //Vcc 98,99
            ucache          = UDigitTransform(data[2], data[3]);
            vcc             = (double)ucache / 10000; //V
            Vcc             = vcc;
            TestingPara.Vcc = Vcc.ToString();

            //Bais 100,101
            ucache           = UDigitTransform(data[4], data[5]);
            bais             = (double)ucache / 500;
            Bias             = bais;
            TestingPara.Bias = Bias.ToString();
            //TxPower 102,103
            ucache  = UDigitTransform(data[6], data[7]);
            txPower = (double)ucache / 10000; //mW
            //取两位有效数字
            TxPower             = Math.Round((Math.Log10(txPower) * 10), 2);
            TestingPara.TxPower = TxPower.ToString();
        }
Пример #10
0
        /// <summary>
        ///   Saves this model to disk using LibSVM's model format.
        /// </summary>
        ///
        /// <param name="stream">The stream where the file should be written.</param>
        ///
        public void Save(Stream stream)
        {
            StreamWriter writer = new StreamWriter(stream);

            writer.WriteLine("solver_type " + Solver.GetDescription().ToUpperInvariant());
            writer.WriteLine("nr_class " + Classes);

            writer.Write("label");
            for (int i = 0; i < Labels.Length; i++)
            {
                writer.Write(" " + Labels[i]);
            }
            writer.WriteLine();

            writer.WriteLine("nr_feature " + Dimension);
            writer.WriteLine("bias " + Bias.ToString("G17", CultureInfo.InvariantCulture));
            writer.WriteLine("w");

            for (int i = 0; i < Weights.Length; i++)
            {
                writer.WriteLine(Weights[i].ToString("G17", CultureInfo.InvariantCulture) + " ");
            }

            writer.Flush();
        }
Пример #11
0
        public void PrepareData()
        {
            InternalArray qint = RunningMean.GetQInt(256);

            RunningMean = qint;
            var cln = RunningVar.Clone();

            for (int i = 0; i < cln.Data.Length; i++)
            {
                cln.Data[i] = (float)Math.Sqrt(cln.Data[i] + eps);
            }
            InternalArray qint2 = cln.GetQInt(256);

            for (int i = 0; i < qint2.QIntData.Length; i++)
            {
                if (qint2.QIntData[i] == 0)
                {
                    qint2.QIntData[i] = 1;
                }
                var q1  = qint2.Unquant(i);
                var err = Math.Abs(q1 - Math.Sqrt(RunningVar.Data[i] + eps));
                if (err > 0.1)
                {
                }
            }
            RunningVar = qint2;

            InternalArray qint3 = Bias.GetQInt(256);

            Bias = qint3;
            InternalArray qint4 = Weight.GetQInt(256);

            Weight = qint4;
        }
Пример #12
0
        public bool SetBias(Bias biasVoltage)
        {
            if (GetBias() != biasVoltage)
            {
                var success    = false;
                var biasNumber = "";
                switch (biasVoltage)
                {
                case Bias.NEG_100PERC: biasNumber = "-100"; break;

                case Bias.NEG_50PERC: biasNumber = "-50"; break;

                case Bias.ZERO: biasNumber = "0"; break;

                case Bias.POS_50PERC: biasNumber = "50"; break;

                case Bias.POS_100PERC: biasNumber = "100"; break;
                }
                mes.SendMessage($"*BIAS{biasNumber}?", (resp) =>
                {
                    ProcessMax4000Response(resp, out success, this.Logger);
                });
                return(success);
            }

            return(true);
        }
Пример #13
0
        /// <summary>
        /// Writes this layer as XML
        /// </summary>
        /// <param name="writer">The XML writer</param>
        public void WriteTo(XmlWriter writer)
        {
            writer.WriteStartElement("layer");
            writer.WriteAttributeString("input-size", InputSize.ToString());
            writer.WriteAttributeString("output-size", OutputSize.ToString());
            writer.WriteAttributeString("activation", Activation.ToString());
            writer.WriteAttributeString("weight-init", WeightInitialisation.ToString());
            writer.WriteAttributeString("regularisation", Regularisation.ToString());
            writer.WriteAttributeString("weight-update", WeightUpdate.ToString());
            writer.WriteAttributeString("trainer", LayerTrainer.ToString());
            writer.WriteAttributeString("lambda", Lambda.ToString());
            writer.WriteAttributeString("momentum", Momentum.ToString());
            writer.WriteAttributeString("decay-rate", DecayRate.ToString());
            writer.WriteAttributeString("decay-rate2", DecayRate2.ToString());
            writer.WriteAttributeString("dropout", Dropout.ToString());
            if (Bias != null)
            {
                Bias.WriteTo("bias", writer);
            }
            if (Weight != null)
            {
                writer.WriteStartElement("weight");
                foreach (var item in Weight)
                {
                    item.WriteTo("row", writer);
                }
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
Пример #14
0
        private Task SetElectrometer(ExcelJob job)
        {
            return(Task.Run(() =>
            {
                if (el == null)
                {
                    MessageBox.Show("No electrometer available!"); return;
                }

                ////ZERO
                //if (!el.IsZeroed() && !alreadyZeroed)
                //{
                //    logger.Log("Zeroing electrometer...");
                //    await el.Zero();
                //}

                //SET RANGE
                if (el.GetRange() != Autodrive.Electrometers.Enums.Range.HIGH)
                {
                    el.SetRange(Autodrive.Electrometers.Enums.Range.HIGH);
                }

                //SET BIAS
                Bias reqBias = Bias.UNKNOWN;
                var currentBias = this.el.GetBias();
                switch (job.Bias)
                {
                case -100:
                case -300: reqBias = Bias.NEG_100PERC; break;

                case -50:
                case -150: reqBias = Bias.NEG_50PERC; break;

                case 0: reqBias = Bias.ZERO; break;

                case 50:
                case 150: reqBias = Bias.POS_50PERC; break;

                case 100:
                case 300: reqBias = Bias.POS_100PERC; break;
                }

                if (reqBias != currentBias)
                {
                    logger.Log($"Settng Bias {reqBias.ToString()} + 10 sec delay");
                    el.SetBias(reqBias);
                    Thread.Sleep(10000);
                }

                //SET MODE
                if (el.GetMode() != MeasureMode.CHARGE)
                {
                    el.SetMode(MeasureMode.CHARGE);
                }
                ;
                el.StopMeasurement();
                el.Reset();
            }));
        }
Пример #15
0
 /// <summary>
 /// Use the specified <paramref name="headCheck"/>, <paramref name="bodyCheck"/>, and <paramref name="tailCheck"/> to represent the valid form of a word, along with the <paramref name="bias"/>.
 /// </summary>
 /// <param name="name">Name to display this pattern as.</param>
 /// <param name="bias">Endian bias of the word. Head bias requires the head if only one letter is present. Tail bias requires the tail if only one letter is present.</param>
 /// <param name="headCheck">A <see cref="Func{T, TResult}"/> to validate the head.</param>
 /// <param name="bodyCheck">A <see cref="Func{T, TResult}"/> to validate the body, which may repeat.</param>
 /// <param name="tailCheck">A <see cref="Func{T, TResult}"/> to validate the tail.</param>
 /// <returns></returns>
 public static Pattern Check(String name, Bias bias, Func <Char, Boolean> headCheck, Func <Char, Boolean> bodyCheck, Func <Char, Boolean> tailCheck)
 {
     if (name is null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     return(new Pattern(new WordChecker(name, bias, headCheck, bodyCheck, tailCheck)));
 }
        public Weights ToWeights()
        {
            var hidden = Hidden.Select(matrix => Matrix.Build.DenseOfArray(matrix)).ToList();
            var bias   = Bias.Select(vector => Vector.Build.DenseOfArray(vector)).ToList();
            var output = Matrix.Build.DenseOfArray(Output);

            return(new Weights(hidden, bias, output));
        }
Пример #17
0
 public void TSSetUp()
 {
     l1        = Utility.Generate <Link>(() => new Link(), 2).ToArray();
     l2        = Utility.Generate <Neuron>(() => new Neuron(new Sigmoid()), 3).ToArray();
     Bias      = new Bias(1);
     Connector = new FullLayerConnector();
     Connector.Connect(l1, l2, Bias);
 }
Пример #18
0
 public void TSSetUp()
 {
     l1   = Utility.Generate <Link>(() => new Link(), 36).ToArray();
     l2   = Utility.Generate <Neuron>(() => new Neuron(new Sigmoid()), 4).ToArray();
     Bias = new Bias(1);
     Cma  = new ConvolutionAuto(4, 1, 1, 2);
     Cma.Connect(l1, l2, Bias);
 }
Пример #19
0
        public ActionResult DeleteConfirmed(int id)
        {
            Bias bias = db.Biases.Find(id);

            db.Biases.Remove(bias);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #20
0
 public TensorOld PrepareTrain(TensorOld input)
 {
     PreparePredict(input);
     BackwardOutput  = input.GetSameShape();
     FiltersGradient = Filters.GetSameShape();
     BiasGradient    = Bias.GetSameShape();
     return(ForwardOutput);
 }
Пример #21
0
        // Apply any deltas that were calculated during back-propogation.
        // The input signals and the bias are all checked for deltas to be applied
        public void ApplyLearning()
        {
            foreach (KeyValuePair <NeuronSignal, NeuralFactor> m in InputSignals)
            {
                m.Value.ApplyWeightChange();
            }

            Bias.ApplyWeightChange();
        }
Пример #22
0
        public override void CopyParametersTo(LayerBase target, float tau)
        {
            base.CopyParametersTo(target, tau);

            var targetDense = target as Dense;

            Weights.CopyTo(targetDense.Weights, tau);
            Bias.CopyTo(targetDense.Bias, tau);
        }
Пример #23
0
        public void InitializeLearning()
        {
            foreach (var m in Input)
            {
                m.Value.ResetWeightChange();
            }

            Bias.ResetWeightChange();
        }
Пример #24
0
        public void ApplyLearning(ref double learningRate)
        {
            foreach (var m in Input)
            {
                m.Value.ApplyWeightChange(ref learningRate);
            }

            Bias.ApplyWeightChange(ref learningRate);
        }
Пример #25
0
        public override void CopyParametersTo(LayerBase target, float tau)
        {
            base.CopyParametersTo(target);

            var targetConv = target as Convolution;

            Kernels.CopyTo(targetConv.Kernels, tau);
            Bias.CopyTo(targetConv.Bias, tau);
        }
Пример #26
0
        public override bool ViewToModel(Point position, out int offset, out Bias bias)
        {
            if (LayoutInvalid)
            {
                offset = -1;
                bias   = Bias.Forward;
                return(false);
            }

            var lineStartOffset   = -1;
            var lineStartPosition = int.MaxValue;
            var lineEndOffset     = -1;
            var lineEndPosition   = 0;

            for (var index = 0; index < lineBreakContent.Count; index++)
            {
                var chunk = lineBreakContent[index];
                var view  = chunk.Chunk;
                if (view.ViewToModel(position, out offset, out bias))
                {
                    return(true);
                }

                if (position.Y >= view.LayoutRect.Y && position.Y < view.LayoutRect.Bottom)
                {
                    if (lineStartPosition > view.LayoutRect.X)
                    {
                        lineStartOffset   = view.Offset;
                        lineStartPosition = view.LayoutRect.X;
                    }
                    if (lineEndPosition < view.LayoutRect.Right)
                    {
                        lineEndOffset   = chunk.EndOffsetWithoutLineBreaks;
                        lineEndPosition = view.LayoutRect.Right;
                    }
                }
            }

            if (position.X <= lineStartPosition)
            {
                offset = lineStartOffset;
                bias   = Bias.Forward;
                return(offset != -1);
            }

            if (position.X >= lineEndPosition)
            {
                offset = lineEndOffset;
                bias   = Bias.Backward;
                return(offset != -1);
            }

            offset = -1;
            bias   = Bias.Forward;
            return(false);
        }
Пример #27
0
        /// <summary>
        /// Apply delta that is calculated in back prop
        /// </summary>
        public void ApplyLearning()
        {
            foreach (var m in InputSignals)//Apply weight change
            {
                m.Value.ApplyWeightChange();
            }

            // Bias for shifting activation function val
            Bias.ApplyWeightChange();
        }
Пример #28
0
 public ActionResult Edit([Bind(Include = "Id,BiasSize")] Bias bias)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bias).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(bias));
 }
Пример #29
0
        public void TSSetUp()
        {
            l1 = Utility.Generate <Link>(() => new Link(), 4704).ToArray();
            l2 = Utility.Generate <Neuron>(() => new Neuron(new Sigmoid()), 1176).ToArray();
            Func <double> wg = () => Weight++;

            Bias = new Bias(1);
            SbSg = new SubSampling(6);
            SbSg.Connect(l1, l2, Bias);
        }
Пример #30
0
        public void TSSetUp()
        {
            l1 = Utility.Generate <Link>(() => new Link(), 841).ToArray();
            l2 = Utility.Generate <Neuron>(() => new Neuron(new Sigmoid()), 1014).ToArray();
            Func <double> wg = () => Weight++;

            Bias = new Bias(1);
            Cma  = new ConvolutionAuto(5, 6, 1, 3);
            Cma.Connect(l1, l2, Bias);
        }