probability finished

This commit is contained in:
dompia5 2024-02-08 02:28:11 +01:00
parent 10ad09a79a
commit 41ac514aa1

View File

@ -17,7 +17,6 @@
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <string>
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
@ -141,6 +140,13 @@ namespace Plant
float temp = (xValue - mean) / sd * sqrt(2);
return (1 + erf(temp)) / 2;
}
float calcProbability2(float xValue, float mean, float sd)
{
float n = sd * 2 * sqrt(3.14); //normalization factor
float p = exp(-pow(xValue - mean, 2) / (2 * pow(sd, 2))); // unnormalized pdf
return p / n;
}
};
}
@ -184,10 +190,12 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector<Plant::Plant> plant
}
sum = NOTHING_SPAWNS_CUTOFF * PRECISION;
int j = 0;
std::cout << "Plant Probabilities:" << std::endl;
for (auto& plant : plants) {
//TODO: add humidity calculations
probability = plant.calcProbability(planet.humidity, plant.humMean, plant.humSD);
probability = plant.calcProbability2(planet.humidity, plant.humMean, plant.humSD)* plant.calcProbability2(planet.temperature, plant.tempMean, plant.tempSD);
std::cout << probability << std::endl;
probability = int(probability * PRECISION);
std::tuple<int,int>probIdPair = std::make_tuple(j ,probability);
probabilities.push_back(probIdPair);
@ -732,8 +740,8 @@ void init(GLFWwindow* window)
loadMTLAndGetTextureID("./models/plant_2_1_small.mtl", plant2_1Material);
loadMTLAndGetTextureID("./models/plant_2_1_small.mtl", plant2_1Material);
plant_specimens.push_back(Plant::Plant(5, 0.99, 5, 1, "plant1_s", "./models/plant_1_1_zmn.obj", plant3Material));
plant_specimens.push_back(Plant::Plant(20, 0.95, 20, 1, "plant1_m", "./models/plant_2_1.obj", plant2_1Material));
plant_specimens.push_back(Plant::Plant(50, 3, 50, 3, "plant1_s", "./models/plant_1_1.obj", plant3Material));
plant_specimens.push_back(Plant::Plant(5, 3, 5, 3, "plant1_m", "./models/plant_2_1.obj", plant2_1Material));
//plant_specimens.push_back(Plant::Plant(1, 0.90, 1, 1, "testPlantCCCCCCCCCCC", "./models/plant_4.ply"));
//plant_specimens.push_back(Plant::Plant(1, 0.5, 1, 1, "testPlantBBBBBBBBB", "./models/plant_4.ply"));