Package org.encog.util.concurrency

Examples of org.encog.util.concurrency.TaskGroup


    int offspringIndex = getPopulation().getPopulationSize()
        - offspringCount;
    final int matingPopulationSize = (int) (getPopulation()
        .getPopulationSize() * getMatingPopulation());

    final TaskGroup group = EngineConcurrency.getInstance()
        .createTaskGroup();

    // mate and form the next generation
    for (int i = 0; i < countToMate; i++) {
      final Genome mother = getPopulation().getGenomes().get(i);
      final int fatherInt = (int) (Math.random() * matingPopulationSize);
      final Genome father = getPopulation().getGenomes().get(fatherInt);
      final Genome child1 = getPopulation().getGenomes().get(
          offspringIndex);
      final Genome child2 = getPopulation().getGenomes().get(
          offspringIndex + 1);

      final MateWorker worker = new MateWorker(mother, father, child1,
          child2);

      if( this.isMultiThreaded() ) {
        EngineConcurrency.getInstance().processTask(worker, group);
      } else {
        worker.run();
      }
     
      offspringIndex += 2;
    }

    if( this.isMultiThreaded() ) {
      group.waitForComplete();
    }

    // sort the next generation
    getPopulation().sort();
  }
View Full Code Here


    Object task;

    this.running = true;
    this.totalTasks = loadWorkload();
    int currentTask = 0;
    TaskGroup group = EngineConcurrency.getInstance().createTaskGroup();

    while (((task = requestNextTask()) != null) && !shouldStop) {
      currentTask++;
      final JobUnitContext context = new JobUnitContext();
      context.setJobUnit(task);
      context.setOwner(this);
      context.setTaskNumber(currentTask);

      final JobUnitWorker worker = new JobUnitWorker(context);
      EngineConcurrency.getInstance().processTask(worker, group);
    }

    group.waitForComplete();
    this.running = false;
    EngineConcurrency.getInstance().checkError();   
  }
View Full Code Here

    this.totalError = 0;

    if (this.workers.length > 1) {

      final TaskGroup group = EngineConcurrency.getInstance()
          .createTaskGroup();

      for (final GradientWorker worker : this.workers) {
        EngineConcurrency.getInstance().processTask(worker, group);
      }

      group.waitForComplete();
    } else {
      this.workers[0].run();
    }

    this.currentError = this.totalError / this.workers.length;
View Full Code Here

        this.workers[0].getNetwork().clearContext();
      }

      if (this.workers.length > 1) {

        final TaskGroup group = EngineConcurrency.getInstance()
            .createTaskGroup();

        for (final ChainRuleWorker worker : this.workers) {
          worker.setOutputNeuron(outputNeuron);
          EngineConcurrency.getInstance().processTask(worker, group);
        }

        group.waitForComplete();
      } else {
        this.workers[0].setOutputNeuron(outputNeuron);
        this.workers[0].run();
      }
     
View Full Code Here

    this.totalError = 0;

    if (this.workers.length > 1) {

      final TaskGroup group = EngineConcurrency.getInstance()
          .createTaskGroup();

      for (final GradientWorker worker : this.workers) {
        EngineConcurrency.getInstance().processTask(worker, group);
      }

      group.waitForComplete();
    } else {
      this.workers[0].run();
    }

    this.setError(this.totalError / this.workers.length);
View Full Code Here

     * Internal method for the iteration of the swarm.
     *
     * @param init  true if this is an initialisation iteration.
     */
    protected void iterationPSO(boolean init) {
        final TaskGroup group = EngineConcurrency.getInstance().createTaskGroup();

        for (int i = 0; i < m_populationSize; i++) {
            NeuralPSOWorker worker = new NeuralPSOWorker(this, i, init);
            if (!init && this.isMultiThreaded()) {
                EngineConcurrency.getInstance().processTask(worker, group);
            } else {
                worker.run();
            }
        }
        if (this.isMultiThreaded()) {
            group.waitForComplete();
        }
        updateGlobalBestPosition();
    }
View Full Code Here

    EngineConcurrency.getInstance().setThreadCount(this.threadCount);

    this.running = true;
    this.totalTasks = loadWorkload();
    int currentTask = 0;
    TaskGroup group = EngineConcurrency.getInstance().createTaskGroup();

    while (((task = requestNextTask()) != null) && !shouldStop) {
      currentTask++;
      final JobUnitContext context = new JobUnitContext();
      context.setJobUnit(task);
      context.setOwner(this);
      context.setTaskNumber(currentTask);

      final JobUnitWorker worker = new JobUnitWorker(context);
      EngineConcurrency.getInstance().processTask(worker, group);
    }

    group.waitForComplete();
    this.running = false;
    EngineConcurrency.getInstance().checkError();   
  }
View Full Code Here

TOP

Related Classes of org.encog.util.concurrency.TaskGroup

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.