Package org.encog.ml.data

Examples of org.encog.ml.data.MLDataPair


    temporal.generate();
   
    Iterator<MLDataPair> itr = temporal.iterator();
   
    // set 0
    MLDataPair pair = itr.next();
    TestCase.assertEquals(10, pair.getInput().size());
    TestCase.assertEquals(1, pair.getIdeal().size());
    TestCase.assertEquals(3.0, pair.getInput().getData(0));
    TestCase.assertEquals(1.5, pair.getInput().getData(1));
    TestCase.assertEquals(3.0, pair.getInput().getData(2));
    TestCase.assertEquals(0.6, pair.getInput().getData(3));
    TestCase.assertEquals(3.0, pair.getInput().getData(4));
    TestCase.assertEquals(0.375, pair.getInput().getData(5));
    TestCase.assertEquals(3.0, pair.getInput().getData(6));
    TestCase.assertEquals(0.25, Math.round(pair.getInput().getData(7)*4.0)/4.0);
    TestCase.assertEquals(3.0, pair.getInput().getData(8));
    TestCase.assertEquals(0.25, Math.round(pair.getInput().getData(9)*4.0)/4.0);
    TestCase.assertEquals(18.0, pair.getIdeal().getData(0));
  }
View Full Code Here


      }
    }

    this.network.setExclude((int) training.getRecordCount());

    final MLDataPair pair = BasicMLDataPair.createPair(
        training.getInputSize(), training.getIdealSize());

    final double[] out = new double[this.network.getOutputCount()];

    for (int r = 0; r < training.getRecordCount(); r++) {
      training.getRecord(r, pair);
      this.network.setExclude(this.network.getExclude() - 1);

      err = 0.0;

      final MLData input = pair.getInput();
      final MLData target = pair.getIdeal();

      if (this.network.getOutputMode() == PNNOutputMode.Unsupervised) {
        if (deriv) {
          final MLData output = computeDeriv(input, target);
          for (int z = 0; z < this.network.getOutputCount(); z++) {
            out[z] = output.getData(z);
          }
        } else {
          final MLData output = this.network.compute(input);
          for (int z = 0; z < this.network.getOutputCount(); z++) {
            out[z] = output.getData(z);
          }
        }
        for (int i = 0; i < this.network.getOutputCount(); i++) {
          diff = input.getData(i) - out[i];
          err += diff * diff;
        }
      } else if (this.network.getOutputMode() == PNNOutputMode.Classification) {
        final int tclass = (int) target.getData(0);
        MLData output;

        if (deriv) {
          output = computeDeriv(input, pair.getIdeal());
        } else {
          output = this.network.compute(input);
        }

        EngineArray.arrayCopy(output.getData(),out);
View Full Code Here

        this.v[vsptr + ivar] = 0.0;
        this.w[wsptr + ivar] = 0.0;
      }
    }

    final MLDataPair pair = BasicMLDataPair.createPair(this.network
        .getSamples().getInputSize(), this.network.getSamples()
        .getIdealSize());

    for (int r = 0; r < this.network.getSamples().getRecordCount(); r++) {

      this.network.getSamples().getRecord(r, pair);

      if (r == this.network.getExclude()) {
        continue;
      }

      dist = 0.0;
      for (ivar = 0; ivar < this.network.getInputCount(); ivar++) {
        diff = input.getData(ivar) - pair.getInput().getData(ivar);
        diff /= this.network.getSigma()[ivar];
        this.dsqr[ivar] = diff * diff;
        dist += this.dsqr[ivar];
      }

      if (this.network.getKernel() == PNNKernelType.Gaussian) {
        dist = Math.exp(-dist);
      } else if (this.network.getKernel() == PNNKernelType.Reciprocal) {
        dist = 1.0 / (1.0 + dist);
      }

      truedist = dist;
      if (dist < 1.e-40) {
        dist = 1.e-40;
      }

      if (this.network.getOutputMode() == PNNOutputMode.Classification) {
        pop = (int) pair.getIdeal().getData(0);
        out[pop] += dist;
        vptr = pop * this.network.getInputCount();
        wptr = pop * this.network.getInputCount();
        for (ivar = 0; ivar < this.network.getInputCount(); ivar++) {
          temp = truedist * this.dsqr[ivar];
          this.v[vptr + ivar] += temp;
          this.w[wptr + ivar] += temp * (2.0 * this.dsqr[ivar] - 3.0);
        }
      }

      else if (this.network.getOutputMode() == PNNOutputMode.Unsupervised) {
        for (ivar = 0; ivar < this.network.getInputCount(); ivar++) {
          out[ivar] += dist * pair.getInput().getData(ivar);
          temp = truedist * this.dsqr[ivar];
          this.v[vsptr + ivar] += temp;
          this.w[wsptr + ivar] += temp
              * (2.0 * this.dsqr[ivar] - 3.0);
        }
        vptr = 0;
        wptr = 0;
        for (outvar = 0; outvar < this.network.getOutputCount(); outvar++) {
          for (ivar = 0; ivar < this.network.getInputCount(); ivar++) {
            temp = truedist * this.dsqr[ivar]
                * pair.getInput().getData(ivar);
            this.v[vptr++] += temp;
            this.w[wptr++] += temp * (2.0 * this.dsqr[ivar] - 3.0);
          }
        }
        psum += dist;
      } else if (this.network.getOutputMode() == PNNOutputMode.Regression) {

        for (ivar = 0; ivar < this.network.getOutputCount(); ivar++) {
          out[ivar] += dist * pair.getIdeal().getData(ivar);
        }
        vptr = 0;
        wptr = 0;
        for (outvar = 0; outvar < this.network.getOutputCount(); outvar++) {
          for (ivar = 0; ivar < this.network.getInputCount(); ivar++) {
            temp = truedist * this.dsqr[ivar]
                * pair.getIdeal().getData(outvar);
            this.v[vptr++] += temp;
            this.w[wptr++] += temp * (2.0 * this.dsqr[ivar] - 3.0);
          }
        }
        for (ivar = 0; ivar < this.network.getInputCount(); ivar++) {
View Full Code Here

    return data.size();
  }

  @Override
  public void getRecord(long index, MLDataPair pair) {
    final MLDataPair source = this.data.get((int) index);
    pair.setInputArray(source.getInputArray());
    if (pair.getIdealArray() != null) {
      pair.setIdealArray(source.getIdealArray());
    }
  }
View Full Code Here

      oseqIterator.next();
    }

    int t = 1;
    while (oseqIterator.hasNext()) {
      final MLDataPair observation = oseqIterator.next();

      for (int i = 0; i < hmm.getStateCount(); i++) {
        computeStep(hmm, observation, t, i);
      }
View Full Code Here

    this.currentState = this.hmm.getStateCount() - 1;
  }

  public MLDataPair observation() {
    final MLDataPair o = this.hmm.getStateDistribution(this.currentState)
        .generate();
    double rand = Math.random();

    for (int j = 0; j < (this.hmm.getStateCount() - 1); j++) {
      if ((rand -= this.hmm
View Full Code Here

   * {@inheritDoc}
   */
  @Override
  public MLDataPair next() {
    if (hasNext()) {
      final MLDataPair pair = BasicMLDataPair.createPair(
          this.owner.getInputSize(), this.owner.getIdealSize());
      this.owner.getRecord(this.currentIndex++, pair);
      return pair;
    } else {
      return null;
View Full Code Here

    if (seqIterator.hasNext()) {
      seqIterator.next();
    }

    for (int t = 1; t < oseq.size(); t++) {
      final MLDataPair observation = seqIterator.next();

      for (int i = 0; i < hmm.getStateCount(); i++) {
        computeAlphaStep(hmm, observation, t, i);
      }
    }
View Full Code Here

    return (int)getRecordCount();
  }

  @Override
  public MLDataPair get(int index) {
    MLDataPair result = BasicMLDataPair.createPair(getInputSize(), getIdealSize());
    this.getRecord(index, result);
    return result;
  }
View Full Code Here

    if (seqIterator.hasNext()) {
      seqIterator.next();
    }

    for (int t = 1; t < oseq.size(); t++) {
      final MLDataPair observation = seqIterator.next();

      for (int i = 0; i < hmm.getStateCount(); i++) {
        computeAlphaStep(hmm, observation, t, i);
      }
      scale(this.ctFactors, this.alpha, t);
View Full Code Here

TOP

Related Classes of org.encog.ml.data.MLDataPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.