From 65dd8160f4d57ad574fa9304c36e16462cafb49a Mon Sep 17 00:00:00 2001 From: edxu96 Date: Wed, 22 May 2019 16:49:11 +0200 Subject: [PATCH] 3.4 --- FuncWindDirec.R | 12 +++++++++--- Output/.DS_Store | Bin 6148 -> 6148 bytes Output/listVecKernalValue_8.csv | 25 +++++++++++++++++++++++++ main.R | 12 ++++++------ 4 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 Output/listVecKernalValue_8.csv diff --git a/FuncWindDirec.R b/FuncWindDirec.R index b0ec96b..2b1c2c3 100644 --- a/FuncWindDirec.R +++ b/FuncWindDirec.R @@ -19,16 +19,22 @@ validateCoefWindDirec <- function(coef, position, vecKernal, listVecKernalValue, return(meanRootMeanSquaredError) } #' Function to calculate the vecCoef -optimWindDirection <- function(ite, listVecKernalValue, vecKernalSeason, numConCoef = 360, datf = datfTrain){ +optimWindDirection <- function(listVecKernalValue, vecKernalSeason, numConCoef = 360, datf = datfTrain){ vecCoef <- rep(1.0, numConCoef) vecObj <- rep(NA, numConCoef) + lenInterval <- 360 / numConCoef for (i in 1:numConCoef) { resultOptim <- optimize(validateCoefWindDirec, position = i, vecKernal = vecKernal, listVecKernalValue = listVecKernalValue, numFold = numFold, datf = datfTrain, lower = 0.6, upper = 1.1) vecCoef[i] <- resultOptim$minimum vecObj[i] <- resultOptim$objective - cat(ite, "-th Iteration. at ", i, ", optimPar = ", vecCoef[i], ", optimObj = ", - vecObj[i], "\n", sep = "") + if (i != 360) { + cat("[", (i - lenInterval/2), ", ", (i + lenInterval/2), "), coef = ", vecCoef[i], ", obj = ", vecObj[i], + "\n", sep = "") + } else { # If i = 360, the half interval after i is 0 + + cat("[", (360 - lenInterval/2), ", ", (0 + lenInterval/2), "), coef = ", vecCoef[i], ", obj = ", vecObj[i], + "\n", sep = "") + } # cat("--------------------------------------------------------------------------------\n") } return(listResult = list(par = vecCoef, obj = vecObj)) diff --git a/Output/.DS_Store b/Output/.DS_Store index 5ac809195fed1c48ce60f05bef03a3b3346c1bac..75708c00451677629ecce9ccaf7600aafc856d62 100644 GIT binary patch delta 107 zcmZoMXfc@J&nU7nU^gS9$Yvg delta 32 ocmZoMXfc@J&nU1lU^gS9z-At%X2#9$nI%{z79?zD=lIJH0H~V^TmS$7 diff --git a/Output/listVecKernalValue_8.csv b/Output/listVecKernalValue_8.csv new file mode 100644 index 0000000..229f1df --- /dev/null +++ b/Output/listVecKernalValue_8.csv @@ -0,0 +1,25 @@ +0.0210382303690308,0.0386676425142392,0.0310216583938252,0.015696265914954,0.0363350940984507,0.00998870012817052,0.0112944005796676,0.0260290432189363,0.0402275194306633,0.0124468070783426 +0.0352575749332934,0.0488454578505528,0.0439763895287604,0.0298201722153239,0.0489681199158422,0.0317351356096721,0.0293380907325416,0.0430415979889779,0.0491679568116819,0.0287895619947852 +0.0559971815589518,0.0695378435852465,0.0675846280781195,0.0524814178389957,0.0712961768207976,0.0629823985205742,0.0529195484051688,0.0664893364751414,0.0735252019435517,0.0531690105427459 +0.0893442625112342,0.105949121488716,0.10563946417481,0.0876918067340077,0.10939066893148,0.106710664204502,0.0873368283476664,0.105236334481422,0.115104801838464,0.0893213559156655 +0.13957503709569,0.162719802296214,0.160820316499347,0.13837356986393,0.168422953470994,0.166087912934495,0.137155334075343,0.165494739548185,0.17581520302309,0.140509769477593 +0.206703602885512,0.238692582521708,0.231897832419802,0.205108731165813,0.247194845594281,0.240856955400443,0.20360138010896,0.245697750395703,0.253048829271636,0.207171304572041 +0.286693988625703,0.326627192565732,0.313925398521119,0.285640565172099,0.338089443857025,0.326515197522194,0.284403594074046,0.338171885359543,0.338958256292166,0.285949045641761 +0.374066741428777,0.418548836197753,0.401100205268535,0.375040587952279,0.432311696446871,0.418138014919203,0.374360741857614,0.433626714731818,0.426536883295075,0.371939238705291 +0.464183527745332,0.510418963336619,0.49069378039878,0.468395698859372,0.524577790459298,0.513653100382026,0.467877308897642,0.525924819639689,0.51520350225715,0.4631251730711 +0.554656702728463,0.601751855806924,0.582050942997468,0.562646438578947,0.613349573876573,0.610390481930788,0.562065783267227,0.613653341209809,0.60662373258643,0.558964213490925 +0.643309938698295,0.689486769015699,0.670739462439627,0.653684014896776,0.697193664769619,0.700266990708416,0.653606303619801,0.696121424014639,0.696021899665157,0.653529856516322 +0.724203714980081,0.766596444387194,0.748453635919083,0.734419648433246,0.771610577043374,0.774237569841544,0.735141282085148,0.768952526117253,0.773800517454363,0.736761556529501 +0.791362822350316,0.82830702725766,0.810134821115374,0.799878975174395,0.831202336763662,0.829976648101091,0.801534229591386,0.827084475431879,0.833642293679814,0.803188754615429 +0.844212832984089,0.874814620893554,0.85785228287589,0.850913793056499,0.874620207173486,0.872621136504899,0.853662018628701,0.870274670222433,0.877166354952476,0.854445534053754 +0.884946970411266,0.90868166108703,0.89564535665553,0.890072899127203,0.905150606392927,0.906705408968001,0.89413659635212,0.901656274858947,0.909916194617604,0.893931166873042 +0.915126208561781,0.932420920142288,0.924350570256389,0.91878063606877,0.927115830328044,0.932360549507103,0.924159207992528,0.924320798941274,0.934639370703153,0.923091770742683 +0.936235209253263,0.948384347393004,0.944089985531686,0.938586921769244,0.943871472089429,0.949651027056354,0.945269799306883,0.941018142972194,0.952315736837455,0.943203478007155 +0.950807953719312,0.960214986118502,0.95744788839918,0.952520359958231,0.957718114551377,0.961453700011347,0.960557280135478,0.954296256232024,0.964848764113336,0.957294397380909 +0.961978876689417,0.970284975869313,0.967229473906325,0.96367451726643,0.968782005521973,0.970470552727708,0.972130367464586,0.965346292502128,0.973853652544989,0.968085988298977 +0.971580257554777,0.978008790625589,0.975163751884829,0.97271190816731,0.976483367053564,0.977879963257077,0.980895071933716,0.974248865387344,0.980432537414922,0.976698860901056 +0.979681941438638,0.983003204468041,0.981962858431013,0.979295511388181,0.981818607114355,0.983927681507391,0.987333215966451,0.981167761951931,0.985476096166605,0.983305494371912 +0.995277202848744,0.996853649028473,0.99616850934611,0.996461356102419,0.997615174511443,0.995883436886899,0.997378755998786,0.997348767025875,0.995584362783285,0.996537018559842 +0.998313132852427,0.999023176124724,0.9984455143167,0.998364472344068,0.998181395207063,0.99868984056449,0.999168010396022,0.998066612520143,0.998809315088422,0.998251956662926 +0.999546856116295,0.999399068753535,1.00116534386101,0.999525984762576,1.0003067906103,0.999403925896767,0.999193468651075,0.999587038478016,0.99936004216005,0.999538043125615 +0.9992351880115,0.998554364881547,1.003322328456,0.999049713789571,0.999294211706312,0.998677196841413,0.998528181589593,1.00101861003783,0.99862095405573,1.00101136236128 diff --git a/main.R b/main.R index cd8a6c6..702d340 100644 --- a/main.R +++ b/main.R @@ -1,7 +1,7 @@ # DTU31761A3: Wind Power Output Prediction using Regression # author: Edward J. Xu # date: May 22th, 2019 -# version: 3.3 +# version: 3.4 # setwd("~/Documents/Github/WindPowerPrediction") ######################################################################################################################## rm(list = ls()) @@ -13,7 +13,7 @@ numFold <- 10 # [number of folds for cross validation] numIte <- 1 # [number of further iterations] if = 1, there is no further iteration to optimize the coeffcients. outputSeries <- 8 # [series number of the output file] wheOutput <- T # [whether to output the results] -wheVali <- F # [whether to validate the result] +wheVali <- T # [whether to validate the result] numConCoef <- 360 # [number of concentration coefficients] if (numIte > 1) { wheFurIte <- T @@ -21,8 +21,8 @@ if (numIte > 1) { wheFurIte <- F # [whether do further iterations] } ## 0.2, Name of the data files -strNameTrain <- "Data/TrainData4.csv" -strNamePred <- "Data/WeatherForecastInput4.csv" +strNameTrain <- "Data/TrainData3.csv" +strNamePred <- "Data/WeatherForecastInput3.csv" strNameVali <- "Data/TrainData4.csv" # Data for validation is the tail data in training data in next session source("Data.R") # All functions needed for Data.R is in FuncData.R ## 0.3, Function Files @@ -48,7 +48,7 @@ cat("---- 3.1, Benchmark without Con-Coef ------------------------------------- mrmseBenchmark <- crossValid(vecKernal, listVecKernalValue, datfTrain, 10) cat("armseBenchmark =", mrmseBenchmark, "\n") cat("---- 3.2, First Iteration -----------------------------------------------------\n") -listResult <- optimWindDirection(1, listVecKernalValue, vecKernalSeason, numConCoef, datfTrain) +listResult <- optimWindDirection(listVecKernalValue, vecKernalSeason, numConCoef, datfTrain) vecCoef <- listResult$par vecObj <- listResult$obj rm(listResult) @@ -72,7 +72,7 @@ if (wheFurIte) { # The speed.center should be updated before every further iteration datfTrain$speed.center <- updateWindSpeedCenter(matCoef[(ite - 1),], datfTrain, numConCoef) datfPred$speed.center <- updateWindSpeedCenter(matCoef[(ite - 1),], datfPred, numConCoef) - listResult <- optimWindDirection(ite, listVecKernalValue, vecKernalSeason, numConCoef, datfTrain) + listResult <- optimWindDirection(listVecKernalValue, vecKernalSeason, numConCoef, datfTrain) matCoef[ite, 1:length(listResult$par)] <- listResult$par matObj[ite, 1:length(listResult$obj)] <- listResult$obj cat("aveARMSE = ", (sqrt(sum((matObj[ite] - mrmseBenchmark)^2)) / numConCoef * 100), "%\n", sep = "")