コード例 #1
0
        public void ActivationTemporal()
        {
            var temporal = new TemporalMLDataSet(5, 1);

            temporal.AddDescription(new TemporalDataDescription(new ActivationTANH(), TemporalDataDescription.Type.Raw,
                                                                true, false));
            temporal.AddDescription(new TemporalDataDescription(new ActivationTANH(), TemporalDataDescription.Type.Raw,
                                                                true, false));
            temporal.AddDescription(new TemporalDataDescription(new ActivationTANH(), TemporalDataDescription.Type.Raw,
                                                                false, true));
            for (int i = 0; i < 10; i++)
            {
                TemporalPoint tp = temporal.CreatePoint(i);
                tp[0] = 1.0 + (i * 3);
                tp[1] = 2.0 + (i * 3);
                tp[2] = 3.0 + (i * 3);
            }

            temporal.Generate();

            IEnumerator <IMLDataPair> itr = temporal.GetEnumerator();

            // set 0
            itr.MoveNext();
            IMLDataPair pair = itr.Current;

            Assert.AreEqual(10, pair.Input.Count);
            Assert.AreEqual(1, pair.Ideal.Count);
            Assert.AreEqual(0.75, Math.Round(pair.Input[0] * 4.0) / 4.0);
            Assert.AreEqual(1.0, Math.Round(pair.Input[1] * 4.0) / 4.0);
            Assert.AreEqual(1.0, Math.Round(pair.Input[2] * 4.0) / 4.0);
            Assert.AreEqual(1.0, Math.Round(pair.Input[3] * 4.0) / 4.0);
        }
コード例 #2
0
        /// <summary>
        /// Get data between two points in raw form.
        /// </summary>
        /// <param name="desc">The data description.</param>
        /// <param name="index">The index to get data from.</param>
        /// <returns>The requested data.</returns>
        private double GetDataRaw(TemporalDataDescription desc,
                                  int index)
        {
            TemporalPoint point = _points[index - 1];

            return(point[desc.Index]);
        }
コード例 #3
0
        /// <summary>
        /// Create a temporal data point using a sequence number. They can also be
        /// created using time. No two points should have the same sequence number.
        /// </summary>
        /// <param name="sequence">The sequence number.</param>
        /// <returns>A new TemporalPoint object.</returns>
        public virtual TemporalPoint CreatePoint(int sequence)
        {
            var point = new TemporalPoint(_descriptions.Count)
            {
                Sequence = sequence
            };

            _points.Add(point);
            return(point);
        }
コード例 #4
0
ファイル: TemporalMLDataSet.cs プロジェクト: losev87/WinForm
        /// <summary>
        /// Get data between two points in raw form.
        /// </summary>
        /// <param name="desc">The data description.</param>
        /// <param name="index">The index to get data from.</param>
        /// <returns>The requested data.</returns>
        private double GetDataRaw(TemporalDataDescription desc,
                                  int index)
        {
            // Note: The reason that we subtract 1 from the index is because we are always one ahead.
            // This allows the DELTA change formatter to work.  DELTA change requires two timeslices,
            // so we have to be one ahead.  RAW only requires one, so we shift backwards.
            TemporalPoint point = _points[index - 1];

            return(point[desc.Index]);
        }
コード例 #5
0
        /// <summary>
        /// Create a temporal point from a time. Using the grandularity each date is
        /// given a unique sequence number. No two dates that fall in the same
        /// grandularity should be specified.
        /// </summary>
        /// <param name="when">The time that this point should be created at.</param>
        /// <returns>The point TemporalPoint created.</returns>
        public virtual TemporalPoint CreatePoint(DateTime when)
        {
            int sequence = GetSequenceFromDate(when);
            var point    = new TemporalPoint(_descriptions.Count)
            {
                Sequence = sequence
            };

            _points.Add(point);
            return(point);
        }
コード例 #6
0
        /// <summary>
        /// Calculate the index to start at.
        /// </summary>
        /// <returns>The starting point.</returns>
        public virtual int CalculateStartIndex()
        {
            for (int i = 0; i < _points.Count; i++)
            {
                TemporalPoint point = _points[i];
                if (IsPointInRange(point))
                {
                    return(i);
                }
            }

            return(-1);
        }
コード例 #7
0
        /// <summary>
        /// Get data between two points in delta form.
        /// </summary>
        /// <param name="desc">The data description.</param>
        /// <param name="index">The index to get data from.</param>
        /// <returns>The requested data.</returns>
        private double GetDataDeltaChange(TemporalDataDescription desc,
                                          int index)
        {
            if (index == 0)
            {
                return(0.0);
            }
            TemporalPoint point         = _points[index];
            TemporalPoint previousPoint = _points[index - 1];

            return(point[desc.Index]
                   - previousPoint[desc.Index]);
        }
コード例 #8
0
        /// <summary>
        /// Get data between two points in percent form.
        /// </summary>
        /// <param name="desc">The data description.</param>
        /// <param name="index">The index to get data from.</param>
        /// <returns>The requested data.</returns>
        private double GetDataPercentChange(TemporalDataDescription desc,
                                            int index)
        {
            if (index == 0)
            {
                return(0.0);
            }
            TemporalPoint point         = _points[index];
            TemporalPoint previousPoint = _points[index - 1];
            double        currentValue  = point[desc.Index];
            double        previousValue = previousPoint[desc.Index];

            return((currentValue - previousValue) / previousValue);
        }
コード例 #9
0
        public void HiLowTemporal()
        {
            var temporal = new TemporalMLDataSet(5, 1);

            temporal.AddDescription(new TemporalDataDescription(TemporalDataDescription.Type.Raw, true, false));
            temporal.AddDescription(new TemporalDataDescription(TemporalDataDescription.Type.Raw, true, false));
            temporal.AddDescription(new TemporalDataDescription(TemporalDataDescription.Type.Raw, false, true));
            for (int i = 0; i < 10; i++)
            {
                TemporalPoint tp = temporal.CreatePoint(i);
                tp[0] = 1.0 + (i * 3);
                tp[1] = 2.0 + (i * 3);
                tp[2] = 3.0 + (i * 3);
            }

            temporal.HighSequence = 8;
            temporal.LowSequence  = 2;
            temporal.Generate();

            Assert.AreEqual(10, temporal.InputNeuronCount);
            Assert.AreEqual(1, temporal.OutputNeuronCount);
            Assert.AreEqual(7, temporal.CalculateActualSetSize());

            IEnumerator <IMLDataPair> itr = temporal.GetEnumerator();

            itr.MoveNext();
            // set 0
            IMLDataPair pair = itr.Current;

            Assert.AreEqual(10, pair.Input.Count);
            Assert.AreEqual(1, pair.Ideal.Count);
            Assert.AreEqual(7.0, pair.Input[0]);
            Assert.AreEqual(8.0, pair.Input[1]);
            Assert.AreEqual(10.0, pair.Input[2]);
            Assert.AreEqual(11.0, pair.Input[3]);
            Assert.AreEqual(13.0, pair.Input[4]);
            Assert.AreEqual(14.0, pair.Input[5]);
            Assert.AreEqual(16.0, pair.Input[6]);
            Assert.AreEqual(17.0, pair.Input[7]);
            Assert.AreEqual(19.0, pair.Input[8]);
            Assert.AreEqual(20.0, pair.Input[9]);
            Assert.AreEqual(24.0, pair.Ideal[0]);
        }
コード例 #10
0
        public void FormatTemporal()
        {
            var temporal = new TemporalMLDataSet(5, 1);

            temporal.AddDescription(new TemporalDataDescription(TemporalDataDescription.Type.DeltaChange, true, false));
            temporal.AddDescription(new TemporalDataDescription(TemporalDataDescription.Type.PercentChange, true, false));
            temporal.AddDescription(new TemporalDataDescription(TemporalDataDescription.Type.Raw, false, true));
            for (int i = 0; i < 10; i++)
            {
                TemporalPoint tp = temporal.CreatePoint(i);
                tp[0] = 1.0 + (i * 3);
                tp[1] = 2.0 + (i * 3);
                tp[2] = 3.0 + (i * 3);
            }

            temporal.Generate();

            IEnumerator <IMLDataPair> itr = temporal.GetEnumerator();

            itr.MoveNext();
            // set 0
            IMLDataPair pair = itr.Current;

            Assert.AreEqual(10, pair.Input.Count);
            Assert.AreEqual(1, pair.Ideal.Count);
            Assert.AreEqual(3.0, pair.Input[0]);
            Assert.AreEqual(1.5, pair.Input[1]);
            Assert.AreEqual(3.0, pair.Input[2]);
            Assert.AreEqual(0.6, pair.Input[3]);
            Assert.AreEqual(3.0, pair.Input[4]);
            Assert.AreEqual(0.375, pair.Input[5]);
            Assert.AreEqual(3.0, pair.Input[6]);
            Assert.AreEqual(0.25, Math.Round(pair.Input[7] * 4.0) / 4.0);
            Assert.AreEqual(3.0, pair.Input[8]);
            Assert.AreEqual(0.25, Math.Round(pair.Input[9] * 4.0) / 4.0);
            Assert.AreEqual(18.0, pair.Ideal[0]);
        }
コード例 #11
0
 /// <summary>
 /// Is the specified point within the range. If a point is in the selection
 /// range, then the point will be used to generate the training sets.
 /// </summary>
 /// <param name="point">The point to consider.</param>
 /// <returns>True if the point is within the range.</returns>
 public virtual bool IsPointInRange(TemporalPoint point)
 {
     return((point.Sequence >= LowSequence) && (point.Sequence <= HighSequence));
 }
コード例 #12
0
        public void BasicTemporal()
        {
            var temporal = new TemporalMLDataSet(5, 1);

            temporal.AddDescription(new TemporalDataDescription(TemporalDataDescription.Type.Raw, true, false));
            temporal.AddDescription(new TemporalDataDescription(TemporalDataDescription.Type.Raw, true, false));
            temporal.AddDescription(new TemporalDataDescription(TemporalDataDescription.Type.Raw, false, true));
            for (int i = 0; i < 10; i++)
            {
                TemporalPoint tp = temporal.CreatePoint(i);
                tp.Data[0] = 1.0 + (i * 3);
                tp.Data[1] = 2.0 + (i * 3);
                tp.Data[2] = 3.0 + (i * 3);
            }

            temporal.Generate();

            Assert.AreEqual(10, temporal.InputNeuronCount);
            Assert.AreEqual(1, temporal.OutputNeuronCount);
            Assert.AreEqual(10, temporal.CalculateActualSetSize());

            IEnumerator <IMLDataPair> itr = temporal.GetEnumerator();

            itr.MoveNext();
            // set 0
            IMLDataPair pair = itr.Current;

            Assert.AreEqual(10, pair.Input.Count);
            Assert.AreEqual(1, pair.Ideal.Count);
            Assert.AreEqual(1.0, pair.Input.Data[0]);
            Assert.AreEqual(2.0, pair.Input.Data[1]);
            Assert.AreEqual(4.0, pair.Input.Data[2]);
            Assert.AreEqual(5.0, pair.Input.Data[3]);
            Assert.AreEqual(7.0, pair.Input.Data[4]);
            Assert.AreEqual(8.0, pair.Input.Data[5]);
            Assert.AreEqual(10.0, pair.Input.Data[6]);
            Assert.AreEqual(11.0, pair.Input.Data[7]);
            Assert.AreEqual(13.0, pair.Input.Data[8]);
            Assert.AreEqual(14.0, pair.Input.Data[9]);
            Assert.AreEqual(18.0, pair.Ideal[0]);

            // set 1
            itr.MoveNext();
            pair = itr.Current;
            Assert.AreEqual(10, pair.Input.Count);
            Assert.AreEqual(1, pair.Ideal.Count);
            Assert.AreEqual(4.0, pair.Input.Data[0]);
            Assert.AreEqual(5.0, pair.Input.Data[1]);
            Assert.AreEqual(7.0, pair.Input.Data[2]);
            Assert.AreEqual(8.0, pair.Input.Data[3]);
            Assert.AreEqual(10.0, pair.Input.Data[4]);
            Assert.AreEqual(11.0, pair.Input.Data[5]);
            Assert.AreEqual(13.0, pair.Input.Data[6]);
            Assert.AreEqual(14.0, pair.Input.Data[7]);
            Assert.AreEqual(16.0, pair.Input.Data[8]);
            Assert.AreEqual(17.0, pair.Input.Data[9]);
            Assert.AreEqual(21.0, pair.Ideal.Data[0]);

            // set 2
            itr.MoveNext();
            pair = itr.Current;
            Assert.AreEqual(10, pair.Input.Count);
            Assert.AreEqual(1, pair.Ideal.Count);
            Assert.AreEqual(7.0, pair.Input.Data[0]);
            Assert.AreEqual(8.0, pair.Input.Data[1]);
            Assert.AreEqual(10.0, pair.Input.Data[2]);
            Assert.AreEqual(11.0, pair.Input.Data[3]);
            Assert.AreEqual(13.0, pair.Input.Data[4]);
            Assert.AreEqual(14.0, pair.Input.Data[5]);
            Assert.AreEqual(16.0, pair.Input.Data[6]);
            Assert.AreEqual(17.0, pair.Input.Data[7]);
            Assert.AreEqual(19.0, pair.Input.Data[8]);
            Assert.AreEqual(20.0, pair.Input.Data[9]);
            Assert.AreEqual(24.0, pair.Ideal.Data[0]);

            // set 3
            itr.MoveNext();
            pair = itr.Current;
            Assert.AreEqual(10, pair.Input.Count);
            Assert.AreEqual(1, pair.Ideal.Count);
            Assert.AreEqual(10.0, pair.Input.Data[0]);
            Assert.AreEqual(11.0, pair.Input.Data[1]);
            Assert.AreEqual(13.0, pair.Input.Data[2]);
            Assert.AreEqual(14.0, pair.Input.Data[3]);
            Assert.AreEqual(16.0, pair.Input.Data[4]);
            Assert.AreEqual(17.0, pair.Input.Data[5]);
            Assert.AreEqual(19.0, pair.Input.Data[6]);
            Assert.AreEqual(20.0, pair.Input.Data[7]);
            Assert.AreEqual(22.0, pair.Input.Data[8]);
            Assert.AreEqual(23.0, pair.Input.Data[9]);
            Assert.AreEqual(27.0, pair.Ideal.Data[0]);
        }