Esempio n. 1
0
void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) {
    auto args = renderContext->args;

    auto primaryFramebuffer = inputs.get0();
    auto lightingModel = inputs.get1();

    if (!_deferredFramebuffer) {
        _deferredFramebuffer = std::make_shared<DeferredFramebuffer>();
    }
    _deferredFramebuffer->updatePrimaryDepth(primaryFramebuffer->getDepthStencilBuffer());

    outputs.edit0() = _deferredFramebuffer;
    outputs.edit1() = _deferredFramebuffer->getLightingFramebuffer();


    gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
        batch.enableStereo(false);
        batch.setViewportTransform(args->_viewport);
        batch.setStateScissorRect(args->_viewport);

        // Clear deferred
        auto deferredFbo = _deferredFramebuffer->getDeferredFramebuffer();
        batch.setFramebuffer(deferredFbo);

        // Clear Color, Depth and Stencil for deferred buffer
        batch.clearFramebuffer(
            gpu::Framebuffer::BUFFER_COLOR0 | gpu::Framebuffer::BUFFER_COLOR1 | gpu::Framebuffer::BUFFER_COLOR2 | gpu::Framebuffer::BUFFER_COLOR3 |
            gpu::Framebuffer::BUFFER_DEPTH |
            gpu::Framebuffer::BUFFER_STENCIL,
            vec4(vec3(0), 0), 1.0, 0.0, true);

        // For the rest of the rendering, bind the lighting model
        batch.setUniformBuffer(LIGHTING_MODEL_BUFFER_SLOT, lightingModel->getParametersBuffer());
    });
}
Esempio n. 2
0
void OutputsTest::test_arrange_names(void) {
  message += "test_arrange_names\n";

  Outputs o;

  Vector<std::string> names = o.arrange_names();

  assert_true(names.size() == 0, LOG);
}
Esempio n. 3
0
void OutputsTest::test_arrange_descriptions(void) {
  message += "test_arrange_descriptions\n";

  Outputs o;

  Vector<std::string> descriptions = o.arrange_descriptions();

  assert_true(descriptions.size() == 0, LOG);
}
Esempio n. 4
0
extern "C" void TIMER32_0_IRQHandler(void)
{
    digitalWrite(PIO3_3, ! digitalRead(PIO3_3));	// Run LED
    if (timer32_0.flags () & 0x01)
    {   // handle SET ports
    	relays.setOutputs();
    }
    if (timer32_0.flags () & 0x02)
    {   // handle CLR ports
    	relays.clrOutputs();
    }
    timer32_0.resetFlags();
}
Esempio n. 5
0
void OutputsTest::test_get_outputs_number(void) {
  message += "test_get_outputs_number\n";

  Outputs o;

  // Test

  o.set();
  assert_true(o.get_outputs_number() == 0, LOG);

  // Test

  o.set(2);
  assert_true(o.get_outputs_number() == 2, LOG);
}
Esempio n. 6
0
void OutputsTest::test_from_XML(void) {
  message += "test_from_XML\n";

  Outputs o;

  tinyxml2::XMLDocument* document;

  // Test

  document = o.to_XML();

  o.from_XML(*document);

  delete document;
}
Esempio n. 7
0
void OutputsTest::test_to_XML(void) {
  message += "test_to_XML\n";

  Outputs o;

  tinyxml2::XMLDocument* document;

  // Test

  document = o.to_XML();

  assert_true(document != NULL, LOG);

  delete document;
}
Esempio n. 8
0
void ResolveNewFramebuffer::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) {
    RenderArgs* args = renderContext->args;
    auto srcFbo = inputs;
    outputs.reset();

    // Check valid src
    if (!srcFbo) {
        return;
    }

    // Check valid size for sr and dest
    auto frameSize(srcFbo->getSize());

    // Resizing framebuffers instead of re-building them seems to cause issues with threaded rendering
    if (_outputFramebuffer && _outputFramebuffer->getSize() != frameSize) {
        _outputFramebuffer.reset();
    }

    if (!_outputFramebuffer) {
        _outputFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("resolvedNew.out"));
        auto colorFormat = gpu::Element::COLOR_SRGBA_32;
        auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR);
        auto colorTexture = gpu::Texture::createRenderBuffer(colorFormat, frameSize.x, frameSize.y, gpu::Texture::SINGLE_MIP, defaultSampler);
        _outputFramebuffer->setRenderBuffer(0, colorTexture);
    }

    gpu::Vec4i rectSrc;
    rectSrc.z = frameSize.x;
    rectSrc.w = frameSize.y;
    gpu::doInBatch("ResolveNew", args->_context, [&](gpu::Batch& batch) { batch.blit(srcFbo, rectSrc, _outputFramebuffer, rectSrc); });

    outputs = _outputFramebuffer;
}
Esempio n. 9
0
void XNodeDefinition::addCalculation( CalculationFunction func,
                            const Inputs &in,
                            const Outputs &out )
  {
  Calculation calc;
  calc.func = func;
  calc.inputIDs = in;
  calc.outputIDs = out;

  XVector<InputID> inVec(in.toVector());
  XVector<OutputID> outVec(out.toVector());

  foreach(const InputID &input, inVec)
    {
    _inputMap[input] << outVec;
    }

  foreach(const OutputID &output, outVec)
    {
    _outputMap[output] << inVec;
    }

  _calculations << calc;
  }
Esempio n. 10
0
extern "C" void PIOINT0_IRQHandler (void)
{
    LPC_GPIO_TypeDef* port = gpioPorts[0];
    port->IC  =  1<<5; // clear the interrupt
    relays.zeroDetectHandler();
}
Esempio n. 11
0
int main(void)
{
   try            
   {
      std::cout << "OpenNN. Yacht Resistance Design Application." << std::endl;	

      srand((unsigned)time(NULL));

      // Data set

      DataSet data_set;

      data_set.set_data_file_name("../data/yachtresistance.dat");

      data_set.load_data();

	  // Variables

	  Variables* variables_pointer = data_set.get_variables_pointer();

	  variables_pointer->set_name(0, "longitudinal_center_buoyancy");
      variables_pointer->set_name(1, "prismatic_coefficient");
	  variables_pointer->set_name(2, "length_displacement_ratio");
	  variables_pointer->set_name(3, "beam_draught_ratio");
	  variables_pointer->set_name(4, "length_beam_ratio");
	  variables_pointer->set_name(5, "froude_number");
	  variables_pointer->set_name(6, "residuary_resistance");

      const Matrix<std::string> inputs_information = variables_pointer->arrange_inputs_information();
      const Matrix<std::string> targets_information = variables_pointer->arrange_targets_information();

	  // Instances 

	  Instances* instances_pointer = data_set.get_instances_pointer();

      instances_pointer->split_random_indices();

      const Vector< Statistics<double> > inputs_statistics = data_set.scale_inputs_minimum_maximum();
      const Vector< Statistics<double> > targets_statistics = data_set.scale_targets_minimum_maximum();

      // Neural network

      const size_t inputs_number = data_set.get_variables().count_inputs_number();
      const size_t hidden_neurons_number = 30;
      const size_t outputs_number = data_set.get_variables().count_targets_number();

      NeuralNetwork neural_network(inputs_number, hidden_neurons_number, outputs_number);

      Inputs* inputs = neural_network.get_inputs_pointer();

      inputs->set_information(inputs_information);

      Outputs* outputs = neural_network.get_outputs_pointer();

      outputs->set_information(targets_information);

      neural_network.construct_scaling_layer();

      ScalingLayer* scaling_layer_pointer = neural_network.get_scaling_layer_pointer();

      scaling_layer_pointer->set_statistics(inputs_statistics);

      scaling_layer_pointer->set_scaling_method(ScalingLayer::NoScaling);

      neural_network.construct_unscaling_layer();

      UnscalingLayer* unscaling_layer_pointer = neural_network.get_unscaling_layer_pointer();

      unscaling_layer_pointer->set_statistics(targets_statistics);

      unscaling_layer_pointer->set_unscaling_method(UnscalingLayer::NoUnscaling);

	  // Performance functional

      PerformanceFunctional performance_functional(&neural_network, &data_set);

	  // Training strategy 

	  TrainingStrategy training_strategy(&performance_functional);

      QuasiNewtonMethod* quasi_Newton_method_pointer = training_strategy.get_quasi_Newton_method_pointer();

      quasi_Newton_method_pointer->set_maximum_iterations_number(1000);

      quasi_Newton_method_pointer->set_reserve_performance_history(true);

      quasi_Newton_method_pointer->set_display_period(100);

      TrainingStrategy::Results training_strategy_results = training_strategy.perform_training();

	  // Testing analysis
                  
      TestingAnalysis testing_analysis(&neural_network, &data_set);

      TestingAnalysis::LinearRegressionResults linear_regression_results = testing_analysis.perform_linear_regression_analysis();

      // Save results

      scaling_layer_pointer->set_scaling_method(ScalingLayer::MinimumMaximum);
      unscaling_layer_pointer->set_unscaling_method(UnscalingLayer::MinimumMaximum);

      data_set.save("../data/data_set.xml");

      neural_network.save("../data/neural_network.xml");
      neural_network.save_expression("../data/expression.txt");

      training_strategy.save("../data/training_strategy.xml");
      training_strategy_results.save("../data/training_strategy_results.dat");

      linear_regression_results.save("../data/linear_regression_analysis_results.dat");

      return(0);
   }
   catch(std::exception& e)
   {
      std::cerr << e.what() << std::endl;

      return(1);
   }
}  
Esempio n. 12
0
int main(void)
{
   try
   {
      std::cout << "OpenNN. Airfoil Self-Noise Application." << std::endl;

      srand((unsigned)time(NULL));

      // Data set

      DataSet data_set;

#ifdef __APPLE__
      data_set.set_data_file_name("../../../../data/airfoil_self_noise.dat");
#else
      data_set.set_data_file_name("../data/airfoil_self_noise.dat");
#endif

      data_set.set_separator("Tab");

      data_set.load_data();

      // Variables

      Variables* variables_pointer = data_set.get_variables_pointer();

      Vector< Variables::Item > variables_items(6);

      variables_items[0].name = "frequency";
      variables_items[0].units = "hertzs";
      variables_items[0].use = Variables::Input;

      variables_items[1].name = "angle_of_attack";
      variables_items[1].units = "degrees";
      variables_items[1].use = Variables::Input;

      variables_items[2].name = "chord_length";
      variables_items[2].units = "meters";
      variables_items[2].use = Variables::Input;

      variables_items[3].name = "free_stream_velocity";
      variables_items[3].units = "meters per second";
      variables_items[3].use = Variables::Input;

      variables_items[4].name = "suction_side_displacement_thickness";
      variables_items[4].units = "meters";
      variables_items[4].use = Variables::Input;

      variables_items[5].name = "scaled_sound_pressure_level";
      variables_items[5].units = "decibels";
      variables_items[5].use = Variables::Target;

      variables_pointer->set_items(variables_items);

      const Matrix<std::string> inputs_information = variables_pointer->arrange_inputs_information();
      const Matrix<std::string> targets_information = variables_pointer->arrange_targets_information();

      // Instances

      Instances* instances_pointer = data_set.get_instances_pointer();

      instances_pointer->split_random_indices();

      const Vector< Statistics<double> > inputs_statistics = data_set.scale_inputs_minimum_maximum();
      const Vector< Statistics<double> > targets_statistics = data_set.scale_targets_minimum_maximum();

      // Neural network

      const size_t inputs_number = variables_pointer->count_inputs_number();
      const size_t hidden_perceptrons_number = 9;
      const size_t outputs_number = variables_pointer->count_targets_number();

      NeuralNetwork neural_network(inputs_number, hidden_perceptrons_number, outputs_number);

      Inputs* inputs = neural_network.get_inputs_pointer();

      inputs->set_information(inputs_information);

      Outputs* outputs = neural_network.get_outputs_pointer();

      outputs->set_information(targets_information);

      neural_network.construct_scaling_layer();

      ScalingLayer* scaling_layer_pointer = neural_network.get_scaling_layer_pointer();

      scaling_layer_pointer->set_statistics(inputs_statistics);

      scaling_layer_pointer->set_scaling_method(ScalingLayer::NoScaling);

      neural_network.construct_unscaling_layer();

      UnscalingLayer* unscaling_layer_pointer = neural_network.get_unscaling_layer_pointer();

      unscaling_layer_pointer->set_statistics(targets_statistics);

      unscaling_layer_pointer->set_unscaling_method(UnscalingLayer::NoUnscaling);

      // Performance functional

      PerformanceFunctional performance_functional(&neural_network, &data_set);

      performance_functional.set_regularization_type(PerformanceFunctional::NEURAL_PARAMETERS_NORM_REGULARIZATION);

      // Training strategy object

      TrainingStrategy training_strategy(&performance_functional);

      QuasiNewtonMethod* quasi_Newton_method_pointer = training_strategy.get_quasi_Newton_method_pointer();

      quasi_Newton_method_pointer->set_maximum_iterations_number(1000);
      quasi_Newton_method_pointer->set_display_period(10);

      quasi_Newton_method_pointer->set_minimum_performance_increase(1.0e-6);

      quasi_Newton_method_pointer->set_reserve_performance_history(true);

      TrainingStrategy::Results training_strategy_results = training_strategy.perform_training();

      // Testing analysis

      TestingAnalysis testing_analysis(&neural_network, &data_set);

      TestingAnalysis::LinearRegressionResults linear_regression_results = testing_analysis.perform_linear_regression_analysis();

      // Save results

      scaling_layer_pointer->set_scaling_method(ScalingLayer::MinimumMaximum);
      unscaling_layer_pointer->set_unscaling_method(UnscalingLayer::MinimumMaximum);

#ifdef __APPLE__
      data_set.save("../../../../data/data_set.xml");

      neural_network.save("../../../../data/neural_network.xml");
      neural_network.save_expression("../../../../data/expression.txt");

      performance_functional.save("../../../../data/performance_functional.xml");

      training_strategy.save("../../../../data/training_strategy.xml");
      training_strategy_results.save("../../../../data/training_strategy_results.dat");

      linear_regression_results.save("../../../../data/linear_regression_analysis_results.dat");
#else
      data_set.save("../data/data_set.xml");

      neural_network.save("../data/neural_network.xml");
      neural_network.save_expression("../data/expression.txt");

      performance_functional.save("../data/performance_functional.xml");

      training_strategy.save("../data/training_strategy.xml");
      training_strategy_results.save("../data/training_strategy_results.dat");

      linear_regression_results.save("../data/linear_regression_analysis_results.dat");
#endif

      return(0);
   }
   catch(std::exception& e)
   {
      std::cerr << e.what() << std::endl;

      return(1);
   }
}
Esempio n. 13
0
int main(void)
{
    try
    {
        int rank = 0;

#ifdef __OPENNN_MPI__

        int size = 1;

        MPI_Init(NULL,NULL);

        MPI_Comm_size(MPI_COMM_WORLD, &size);

        MPI_Comm_rank(MPI_COMM_WORLD, &rank);

#endif

        if(rank == 0)
        {
            std::cout << "OpenNN. Yacht Resistance Design Application." << std::endl;
        }

        srand((unsigned)time(NULL));

        // Global variables

        DataSet data_set;

        NeuralNetwork neural_network;

        LossIndex loss_index;

        TrainingStrategy training_strategy;

        // Local variables

        DataSet local_data_set;

        NeuralNetwork local_neural_network;

        LossIndex local_loss_index;

        TrainingStrategy local_training_strategy;

        if(rank == 0)
        {
            // Data set

            data_set.set_data_file_name("../data/yachtresistance.dat");

            data_set.load_data();

            // Variables

            Variables* variables_pointer = data_set.get_variables_pointer();

            variables_pointer->set_name(0, "longitudinal_center_buoyancy");
            variables_pointer->set_name(1, "prismatic_coefficient");
            variables_pointer->set_name(2, "length_displacement_ratio");
            variables_pointer->set_name(3, "beam_draught_ratio");
            variables_pointer->set_name(4, "length_beam_ratio");
            variables_pointer->set_name(5, "froude_number");
            variables_pointer->set_name(6, "residuary_resistance");

            const Matrix<std::string> inputs_information = variables_pointer->arrange_inputs_information();
            const Matrix<std::string> targets_information = variables_pointer->arrange_targets_information();

            // Instances

            Instances* instances_pointer = data_set.get_instances_pointer();

            instances_pointer->split_random_indices();

            const Vector< Statistics<double> > inputs_statistics = data_set.scale_inputs_minimum_maximum();
            const Vector< Statistics<double> > targets_statistics = data_set.scale_targets_minimum_maximum();

            // Neural network

            const size_t inputs_number = data_set.get_variables().count_inputs_number();
            const size_t hidden_neurons_number = 30;
            const size_t outputs_number = data_set.get_variables().count_targets_number();

            neural_network.set(inputs_number, hidden_neurons_number, outputs_number);

            Inputs* inputs = neural_network.get_inputs_pointer();

            inputs->set_information(inputs_information);

            Outputs* outputs = neural_network.get_outputs_pointer();

            outputs->set_information(targets_information);

            neural_network.construct_scaling_layer();

            ScalingLayer* scaling_layer_pointer = neural_network.get_scaling_layer_pointer();

            scaling_layer_pointer->set_statistics(inputs_statistics);

            scaling_layer_pointer->set_scaling_method(ScalingLayer::NoScaling);

            neural_network.construct_unscaling_layer();

            UnscalingLayer* unscaling_layer_pointer = neural_network.get_unscaling_layer_pointer();

            unscaling_layer_pointer->set_statistics(targets_statistics);

            unscaling_layer_pointer->set_unscaling_method(UnscalingLayer::NoUnscaling);

            // Loss index

            loss_index.set_data_set_pointer(&data_set);
            loss_index.set_neural_network_pointer(&neural_network);

            // Training strategy

            training_strategy.set(&loss_index);

            QuasiNewtonMethod* quasi_Newton_method_pointer = training_strategy.get_quasi_Newton_method_pointer();

            quasi_Newton_method_pointer->set_maximum_iterations_number(1000);

            quasi_Newton_method_pointer->set_reserve_loss_history(true);

            quasi_Newton_method_pointer->set_display_period(100);
        }

#ifdef __OPENNN_MPI__
        MPI_Barrier(MPI_COMM_WORLD);

        local_data_set.set_MPI(&data_set);

        local_neural_network.set_MPI(&neural_network);

        local_loss_index.set_MPI(&local_data_set,&local_neural_network,&loss_index);

        local_training_strategy.set_MPI(&local_loss_index,&training_strategy);

        MPI_Barrier(MPI_COMM_WORLD);

        TrainingStrategy::Results training_strategy_results = local_training_strategy.perform_training();
#else
        TrainingStrategy::Results training_strategy_results = training_strategy.perform_training();
#endif

        if(rank == 0)
        {
#ifdef __OPENNN_MPI__
            neural_network.set_multilayer_perceptron_pointer(local_neural_network.get_multilayer_perceptron_pointer());
#endif
            // Testing analysis

            TestingAnalysis testing_analysis(&neural_network, &data_set);

            TestingAnalysis::LinearRegressionResults linear_regression_results = testing_analysis.perform_linear_regression_analysis();

            // Save results

            ScalingLayer* scaling_layer_pointer = neural_network.get_scaling_layer_pointer();
            UnscalingLayer* unscaling_layer_pointer = neural_network.get_unscaling_layer_pointer();

            scaling_layer_pointer->set_scaling_method(ScalingLayer::MinimumMaximum);
            unscaling_layer_pointer->set_unscaling_method(UnscalingLayer::MinimumMaximum);

            data_set.save("../data/data_set.xml");

            neural_network.save("../data/neural_network.xml");
            neural_network.save_expression("../data/expression.txt");

            training_strategy.save("../data/training_strategy.xml");
            training_strategy_results.save("../data/training_strategy_results.dat");

            linear_regression_results.save("../data/linear_regression_analysis_results.dat");
        }

#ifdef __OPENNN_MPI__

        MPI_Barrier(MPI_COMM_WORLD);

        MPI_Finalize();

#endif
        return(0);
    }
    catch(std::exception& e)
    {
        std::cerr << e.what() << std::endl;

        return(1);
    }
}