添加熵值法c语言文件

main
PeterAlbus 2 years ago
parent 0af70a0d20
commit 4c6d1a2aba

1
.gitignore vendored

@ -33,3 +33,4 @@ build/
.vscode/
/src/main/resources/5963105_www.peteralbus.com.pfx
/src/main/resources/application.yml
/src/main/resources/8128048_www.peteralbus.com.pfx

@ -0,0 +1,117 @@
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
clock_t start, finish;
double duration;
start = clock();
double x[10][4]={{6.962645,67101,730.3979,1.3},
{5.643831,50732,170.8517,1.7},
{7.775079,39755,89.2054,1},
{6.568763,67101,294.3379,1},
{6.552100,67101,281.1741,1.9},
{6.669364,43274,41.5144,1.2},
{7.774892,39755,89.2054,1.4},
{6.511145,67101,518.4596,1.4},
{6.966898,67101,382.3772,1.7},
{5.894564,35641,374.3219,1.2}};
double max[4];
double min[4];
double sum[4];
for(int i=0;i<4;i++)
{
max[i]=x[0][i];
min[i]=x[0][i];
sum[i]=x[0][i];
for(int j=1;j<10;j++)
{
if(x[j][i]>max[i])
{
max[i]=x[j][i];
}
if(x[j][i]<min[i])
{
min[i]=x[j][i];
}
sum[i]+=x[j][i];
}
}
double x_normalize[10][4];
for(int i=0;i<10;i++)
{
for(int j=0;j<4;j++)
{
if(j==1)
{
x_normalize[i][j]=(max[j]-x[i][j])/(max[j]-min[j]);
}
else
{
x_normalize[i][j]=(x[i][j]-min[j])/(max[j]-min[j]);
}
cout<<setw(15)<<x_normalize[i][j]<<",";
}
cout<<endl;
}
cout<<endl;
cout<<endl;
double p[10][4];
for(int i=0;i<10;i++)
{
for(int j=0;j<4;j++)
{
p[i][j]=x_normalize[i][j]/sum[j]+0.0000001;
cout<<setw(15)<<p[i][j]<<",";
}
cout<<endl;
}
cout<<endl;
cout<<endl;
double e[4];
double sumG=0;
for(int j=0;j<4;j++)
{
double sumJ=0;
for(int i=0;i<10;i++)
{
sumJ+=p[i][j]*log(p[i][j]);
}
e[j]=(-1/log(10))*sumJ;
sumG+=(1-e[j]);
cout<<setw(15)<<e[j]<<",";
}
cout<<endl;
cout<<endl;
double a[4];
for(int i=0;i<4;i++)
{
a[i]=(1-e[i])/sumG;
cout<<setw(15)<<a[i]<<",";
}
cout<<endl;
cout<<endl;
double weights[10];
double sumW=0;
for(int i=0;i<10;i++)
{
double weight=0;
for(int j=0;j<4;j++)
{
weight+=(a[j]*p[i][j]);
}
weights[i]=weight;
sumW+=weight;
}
for(int i=0;i<10;i++)
{
cout<<weights[i]/sumW<<",";
}
cout<<endl;
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf("%f seconds\n", duration);
return 0;
}

@ -1,25 +1,77 @@
package com.peteralbus;
import com.peteralbus.entity.EarthquakeInfo;
import com.peteralbus.entity.Estimate;
import com.peteralbus.service.EarthquakeInfoService;
import com.peteralbus.service.EstimateService;
import com.peteralbus.util.EstimateUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@SpringBootTest
class EarthquickApplicationTests
{
@Autowired
EstimateService estimateService;
@Autowired
EstimateUtil estimateUtil;
@Autowired
EarthquakeInfoService earthquakeInfoService;
@Test
void contextLoads()
{
// long startTime = System.currentTimeMillis();
// Map<String, Object> mapParameter = new HashMap<String, Object>();
// mapParameter.put("earthquakeId",16);
// EarthquakeInfo earthquakeInfo=earthquakeInfoService.queryInfoWithLine(mapParameter).get(0);
// double magnitude = earthquakeInfo.getMagnitude(),
// highIntensity = earthquakeInfo.getHighIntensity(),
// longitude = earthquakeInfo.getLongitude(),
// latitude = earthquakeInfo.getLatitude(),
// longRadius = earthquakeInfo.getIntensityLineList().get(2).getLongRadius(),
// shortRadius = earthquakeInfo.getIntensityLineList().get(2).getShortRadius();
// System.out.println(longRadius);
// LocalDateTime earthquakeTime = earthquakeInfo.getEarthquakeTime();
// //将角度转换为弧度。
// double radians = Math.toRadians(latitude);
// double minLongitude = longitude-shortRadius/(111-Math.cos(radians)),
// maxLongitude = longitude+shortRadius/(111-Math.cos(radians)),
// minLatitude = latitude-longRadius/111,
// maxLatitude = latitude+longRadius/111;
// int population=(int)estimateService.getPopulation(minLongitude,maxLongitude,minLatitude,maxLatitude);
// double death=estimateUtil.deathPredict(earthquakeInfo.getEarthquakeId(),population,magnitude,highIntensity,earthquakeTime,longitude,latitude);
// long endTime = System.currentTimeMillis();
// long usedTime = (endTime-startTime)/1000;
// System.out.println(death + " " + usedTime);
// getPopulation(100.7342,25.5736);
// getPopulation(99.9586,25.6753);
// getPopulation(100.1926,25.9121);
// getPopulation(100.1885,25.9252);
// getPopulation(99.7768,25.3342);
// getPopulation(99.9586,25.6752);
// getPopulation(100.3105,25.6775);
// getPopulation(100.1209,25.7921);
// getPopulation(100.4937,25.3366);
}
void getPopulation(double longitude,double latitude)
{
double minLongitude = longitude-0.1,
maxLongitude = longitude+0.1,
minLatitude = latitude-0.1,
maxLatitude = latitude+0.1;
System.out.println(estimateService.getPopulation(minLongitude, maxLongitude, minLatitude, maxLatitude));
}
}

Loading…
Cancel
Save