changes
This commit is contained in:
parent
5a208e116f
commit
585522b4df
Binary file not shown.
3
Game1/Content/ML/report_Joel
Normal file
3
Game1/Content/ML/report_Joel
Normal file
@ -0,0 +1,3 @@
|
||||
Mean Absolute Error: 0.0108015636096701
|
||||
Mean Squared Error: 0.0434908452113952
|
||||
R Squared: 0.702723944791744
|
@ -72,9 +72,9 @@ class Farm
|
||||
init(Size, housepos);
|
||||
RainPosition.X = r.Next(0, 1900);
|
||||
RainPosition.Y = r.Next(0, 1950);
|
||||
RainPosition.X = 5;
|
||||
RainPosition.Y = 5;
|
||||
RainfallMap = PerlinNoise.LoadImage("C:\\Users\\Joel\\source\\repos\\Oskars Repo\\Game1\\Content\\Rainfall.png");
|
||||
RainPosition.X = 1000;
|
||||
RainPosition.Y = 1000;
|
||||
//RainfallMap = PerlinNoise.LoadImage("C:\\Users\\Joel\\source\\repos\\Oskars Repo\\Game1\\Content\\Rainfall.png");
|
||||
RainfallMap = PerlinNoise.LoadImage("C:/Users/Oskar/source/repos/PotatoPlanFinal/Game1/Content/Rainfall.png");
|
||||
}
|
||||
|
||||
@ -100,10 +100,12 @@ class Farm
|
||||
public Rectangle getDestinationRectangle(int x, int y, Vector2 Size)
|
||||
{
|
||||
Vector2 temp = new Vector2((int)Math.Round(RainPosition.X), (int)Math.Round(RainPosition.Y));
|
||||
if (RainPosition.X >= 1999 - Size.X)
|
||||
temp.X = (Size.X) - (1999 - (int)Math.Round(RainPosition.X));
|
||||
if (RainPosition.Y >= 1999 - Size.Y)
|
||||
temp.Y = (Size.Y) - (1999 - (int)Math.Round(RainPosition.Y));
|
||||
if (RainPosition.X >= 1999 - x)
|
||||
temp.X = (1999 - (int)Math.Round(RainPosition.X));
|
||||
//temp.X = temp.X + (x+1);
|
||||
if (RainPosition.Y >= 1999 - y)
|
||||
temp.Y = (1999 - (int)Math.Round(RainPosition.Y));
|
||||
//temp.Y = temp.Y + (y+1);
|
||||
return new Rectangle(x + (int)temp.X, y + (int)temp.Y, 1, 1);
|
||||
}
|
||||
|
||||
@ -124,10 +126,10 @@ class Farm
|
||||
for (int j = 0; j < Size.Y; j++)
|
||||
{
|
||||
Vector2 temp = new Vector2((int)Math.Round(RainPosition.X), (int)Math.Round(RainPosition.Y));
|
||||
if (RainPosition.X >= 1999 - Size.X)
|
||||
temp.X = (Size.X) - (1999 - (int)Math.Round(RainPosition.X));
|
||||
if (RainPosition.Y >= 1999 - Size.Y)
|
||||
temp.Y = (Size.Y) - (1999 - (int)Math.Round(RainPosition.Y));
|
||||
if (RainPosition.X >= 1999 - i)
|
||||
temp.X = (1999 - (int)Math.Round(RainPosition.X));
|
||||
if (RainPosition.Y >= 1999 - j)
|
||||
temp.Y = (1999 - (int)Math.Round(RainPosition.Y));
|
||||
crops[i, j].updateCrop(Size, RainfallMap[(int)Math.Round(temp.X) + i][(int)Math.Round(temp.Y) + j].GetBrightness());
|
||||
}
|
||||
}
|
||||
@ -174,7 +176,7 @@ class Farm
|
||||
float x, y;
|
||||
x = WindSpeed.X + GetRandomNumber(-1f, 1f) / 2000;
|
||||
y = WindSpeed.Y + GetRandomNumber(-1f, 1f) / 2000;
|
||||
x = -0.02f;
|
||||
//x = 0.02f;
|
||||
if (x <= 1f && x >= -1f)
|
||||
{
|
||||
WindSpeed.X = x;
|
||||
@ -255,11 +257,15 @@ class Farm
|
||||
|
||||
public Color getRainAmount(int x, int y, Color color, Vector2 Size)
|
||||
{
|
||||
Vector2 temp = new Vector2(x + (int)Math.Round(RainPosition.X), y + (int)Math.Round(RainPosition.Y));
|
||||
if (RainPosition.X >= 1999 - Size.X)
|
||||
temp.X = (Size.X) - (1999 - (int)Math.Round(RainPosition.X));
|
||||
if (RainPosition.Y >= 1999 - Size.Y)
|
||||
temp.Y = (Size.Y) - (1999 - (int)Math.Round(RainPosition.Y));
|
||||
Vector2 temp = new Vector2((int)Math.Round(RainPosition.X), (int)Math.Round(RainPosition.Y));
|
||||
if (RainPosition.X >= 1999 - (x + 1))
|
||||
temp.X = (1999 - (int)Math.Round(RainPosition.X));
|
||||
temp.X = temp.X + (x + 1);
|
||||
|
||||
if (RainPosition.Y >= 1999 - (y + 1))
|
||||
temp.Y = (1999 - (int)Math.Round(RainPosition.Y));
|
||||
temp.Y = temp.Y + (y + 1);
|
||||
|
||||
if (RainfallMap[(int)temp.X][(int)temp.Y].GetBrightness() < 0.4f)
|
||||
{
|
||||
return Color.FromNonPremultiplied(color.R, color.G, color.B, (int)(0));
|
||||
|
@ -53,10 +53,6 @@ namespace Game1.Sources.ML_Joel
|
||||
NumberOfLeaves = 55,
|
||||
LabelColumnName = "Production",
|
||||
FeatureColumnName = "Features",
|
||||
//EarlyStoppingRound = 20,
|
||||
//UseCategoricalSplit = true,
|
||||
//L2CategoricalRegularization = 1,
|
||||
//CategoricalSmoothing = 1,
|
||||
|
||||
Booster = new DartBooster.Options()
|
||||
{
|
||||
@ -68,20 +64,13 @@ namespace Game1.Sources.ML_Joel
|
||||
.Text.FeaturizeText("SeasonF", "Season")
|
||||
.Append(mlContext.Transforms.Text.FeaturizeText("CropF", "Crop"))
|
||||
.Append(mlContext.Transforms.Concatenate("Features", "SeasonF", "CropF", "Rainfall"))
|
||||
//.Append(mlContext.Transforms.Conversion.MapValueToKey("ProductionF", "Production"), TransformerScope.TrainTest)
|
||||
//.AppendCacheCheckpoint(mLContext)
|
||||
.AppendCacheCheckpoint(mLContext)
|
||||
.Append(mLContext.Regression.Trainers.LightGbm(options));
|
||||
//.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel", "PredictedLabel"));
|
||||
|
||||
//Evaluate(mlContext, trainingDataView, pipeline, 10, reportPath, "ProductionF");
|
||||
//var Evaluate = mlContext.Regression.CrossValidate(trainingDataView, pipeline, numberOfFolds: 100, labelColumnName: "Production");
|
||||
//var Evaluate = mlContext.Regression.Evaluate(testDataView, labelColumnName: "Production", scoreColumnName: "Score");
|
||||
//var metricsInMultipleFolds = Evaluate.Select(r => r.Metrics);
|
||||
|
||||
ITransformer MLModel = pipeline.Fit(trainingDataView);
|
||||
var testEval = MLModel.Transform(testDataView);
|
||||
var Evaluate = mlContext.Regression.Evaluate(testEval, labelColumnName: "Production");
|
||||
|
||||
Evaluate(mlContext, testEval, pipeline, 10, reportPath, "Production");
|
||||
|
||||
return MLModel;
|
||||
}
|
||||
@ -95,19 +84,10 @@ namespace Game1.Sources.ML_Joel
|
||||
// Evaluate and save results to a text file
|
||||
public static void Evaluate(MLContext mlContext, IDataView trainingDataView, IEstimator<ITransformer> trainingPipeline, int folds, string reportPath, string labelColumnName)
|
||||
{
|
||||
var crossVal = mlContext.MulticlassClassification.CrossValidate(trainingDataView, trainingPipeline, numberOfFolds: folds, labelColumnName: labelColumnName);
|
||||
|
||||
var metricsInMultipleFolds = crossVal.Select(r => r.Metrics);
|
||||
|
||||
var MicroAccuracyValues = metricsInMultipleFolds.Select(m => m.MicroAccuracy);
|
||||
var LogLossValues = metricsInMultipleFolds.Select(m => m.LogLoss);
|
||||
var LogLossReductionValues = metricsInMultipleFolds.Select(m => m.LogLossReduction);
|
||||
string MicroAccuracyAverage = MicroAccuracyValues.Average().ToString("0.######");
|
||||
string LogLossAvg = LogLossValues.Average().ToString("0.######");
|
||||
string LogLossReductionAvg = LogLossReductionValues.Average().ToString("0.######");
|
||||
var eval = mlContext.Regression.Evaluate(trainingDataView, labelColumnName: labelColumnName);
|
||||
|
||||
var report = File.CreateText(reportPath);
|
||||
report.Write("Micro Accuracy: " + MicroAccuracyAverage + '\n' + "LogLoss Average: " + LogLossAvg + '\n' + "LogLoss Reduction: " + LogLossReductionAvg, 0, 0);
|
||||
report.Write("Mean Absolute Error: " + eval.MeanAbsoluteError + '\n' + "Mean Squared Error: " + eval.MeanSquaredError + '\n' + "R Squared: " + eval.RSquared, 0, 0);
|
||||
report.Flush();
|
||||
report.Close();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user