summaryrefslogtreecommitdiff
path: root/exp_3.cpp
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2022-07-01 02:40:08 +0800
committerKunoiSayami <[email protected]>2022-07-01 02:40:08 +0800
commit8ae4020a88a0f2192274e6d6543b692220e65e52 (patch)
tree92d803c6a6da089514dc802984a66911f18795f6 /exp_3.cpp
parent0b2735596e8969c08797f18977c626f423b3ab6d (diff)
feat(script): Swift normal distribution lower to zero
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'exp_3.cpp')
-rw-r--r--exp_3.cpp62
1 files changed, 23 insertions, 39 deletions
diff --git a/exp_3.cpp b/exp_3.cpp
index bda5681..26e14e5 100644
--- a/exp_3.cpp
+++ b/exp_3.cpp
@@ -10,6 +10,7 @@ constexpr size_t length = 1048576;
constexpr size_t sample_length = 1000;
#define CALC_HEIGHT
+#define CALC_CDF_DIFF
#ifdef CALC_HEIGHT
constexpr int block_size = 2;
@@ -62,16 +63,27 @@ long double sample_cdf(long double x) {
(long double)(sample_vector.size() - 1);
}
-int infer_offset(double x) {
+int infer_offset(long double x) {
return int(sample_cdf(x) * double(population_vector.size()));
}
+#ifdef CALC_CDF_DIFF
+int infer_offset_from_cdf(long double cdf) {
+ return int(cdf * double(population_vector.size()));
+}
// const double M_SQRT1_2 = sqrt(0.5);
constexpr long long s_avg = 2147483648;
constexpr long long s_stddev = 2147483648;
-double goal_cdf(double x) { return erfc(-x * M_SQRT1_2) * 0.5; }
-double stat_cdf(double x) { return goal_cdf((x - s_avg) / s_stddev); }
+long double goal_cdf(long double x) { return std::erfc(-x * M_SQRT1_2) * 0.5; }
+long double stat_cdf(long double x) { return goal_cdf((x - s_avg) / s_stddev); }
+
+long double finite_population_cdf(long double x) {
+ auto it = upper_bound(population_vector.begin(), population_vector.end(), x);
+ return (long double)(it - population_vector.begin()) /
+ population_vector.size();
+}
+#endif
int main() {
@@ -109,45 +121,17 @@ int main() {
for (auto iter = population_vector.begin(); iter != population_vector.end();
iter++) {
+#ifdef CALC_CDF_DIFF
+ auto cdf = sample_cdf(*iter);
+ printf("%d,%d,%.6Lf ", getHeight(infer_offset_from_cdf(cdf)),
+ getHeight(iter - population_vector.begin()),
+ std::abs(cdf - stat_cdf(*iter)));
+#else
printf("%d,%d ", getHeight(infer_offset(*iter)),
getHeight(iter - population_vector.begin()));
+#endif
+ fflush(stdout);
}
puts("");
return 0;
-
- /*auto ita = set2.begin(), itb = set2.begin();
- itb++;
- long double dx = (*itb - *ita);
- int cnt1 = 0, cnt2 = 0;
- // for (auto it = set2.begin(); it != set2.end(); it++) printf("%lld ", *it);
- // printf("\n");
- long double e = 0;
- for (auto iter = set1.begin(); iter != set1.end(); iter++, cnt1++) {
- if (*iter <= *set2.begin()) {
- e += fabs(0.0 - double(cnt1) / (length - 1));
- printf("%.4lf ", 0.0);
- continue;
- }
- while (itb != set2.end() && *iter > *itb)
- ita++, itb++, dx = (*itb - *ita), cnt2++;
- if (*itb == *set2.end()) {
- e += fabs(1.0 - double(cnt1) / (length - 1));
- printf("%.4lf ", 100.0);
- continue;
- }
- // printf("%lld %lld %lld ", *ita, *it, *itb);
- long double res = (cnt2 + (*iter - *ita) / dx) / (sample_length - 1);
- auto single_e = std::abs(res - (long double)cnt1 / (length - 1));
- auto real_cnt2 = res * (length - 1) + 1;
- location.emplace_back(getHeight(cnt1),
- getHeight((int)std::round(real_cnt2)), single_e);
- e += single_e;
- printf("%.4Lf ", res * 100);
- }
- printf("\n%.4Lf\n", e);
- for (auto element : location) {
- printf("%d,%d ", std::get<0>(element), std::get<1>(element));
- }
- puts("");
- return 0;*/
} \ No newline at end of file