如何重新分配我的体重,以使预期结果相同。

huangapple go评论62阅读模式
英文:

How can I re distribute my weight such that expected outcome is the same

问题

I want to calculate expected outcome after resting a price, I tried using scaling matrix but it did not work. Appreciate any help.

double originalPrice = {5, 8, 18, 58, 80, 49.399167162403300}

double originalWeight = {0.34146341463414637, 0.3902439024390244, 0.14634146341463414, 0.024390243902439025, 0.024390243902439025, 0.07317073170731707}

after some iterations iterations my new prices and new weights are now,

double newPrices1 = [7.0, 8.0, 20.0, 58.0, 81.0, 49.3991671624033]
double newWeight1 =  [0.3575704958570497, 0.3902439024390244, 0.15629694702450886, 0.024390243902439025, 0.024390243902439025, 0.04710816687453892]

note: the EX (expected value) of originalPrice and newPrice1 is the same, you calculate by taking the product of respective price to respective weight and then take the total sum of it.

in the next iteration the first price returns to its original value e.g we call it newPrices2

double newPrices2 = [5.0, 8.0, 20.0, 58.0, 82.0, 49.3991671624033]

I want to find new weights, that would keep my expected outcome the same

double newWeight2 = [x1,x2,x3,x4,x5,x6]

I tried scaling the vectors but it did not help, here is the code algorithm i tried.

public static double[] redistributeWeight(double[] prices, 
 double[] weights, double[] originalWeights) {
        double totalOriginalPrice = 0.0;
        double totalCurrentPrice = 0.0;

        // Calculate the total original price and current price
        for (int i = 0; i < prices.length; i++) {
            totalOriginalPrice += originalWeights[i] * prices[i];
            totalCurrentPrice += weights[i] * prices[i];
        }

        // Calculate the scaling factor
        double scaleFactor = totalOriginalPrice / totalCurrentPrice;

        // Redistribute the weights based on the scaling factor
        for (int i = 0; i < weights.length; i++) {
            weights[i] *= scaleFactor;
        }

        return weights;
    }
英文:

I want to calculate expected outcome after resting a price, I tried using scaling matrix but it did not work. Appreciate any help.

double originalPrice = {5, 8, 18, 58, 80, 49.399167162403300}

double originalWeight = {0.34146341463414637, 0.3902439024390244, 0.14634146341463414, 0.024390243902439025, 0.024390243902439025, 0.07317073170731707}

after some iterations iterations my new prices and new weights are now,

double newPrices1 = [7.0, 8.0, 20.0, 58.0, 81.0, 49.3991671624033]
double newWeight1 =  [0.3575704958570497, 0.3902439024390244, 0.15629694702450886, 0.024390243902439025, 0.024390243902439025, 0.04710816687453892]

note: the EX (expected value) of originalPrice and newPrice1 is the same, you calculate by taking the product of respective price to respective weight and then take the total sum of it.

in the next iteration the first price returns to its original value e.g we call it newPrices2

double newPrices2 = [5.0, 8.0, 20.0, 58.0, 82.0, 49.3991671624033]

I want to find new weights, that would keep my expected outcome the same

double newWeight2 = [x1,x2,x3,x4,x5,x6]

I tried scaling the vectors but it did not help, here is the code algorithm i tried.

public static double[] redistributeWeight(double[] prices, 
 double[] weights, double[] originalWeights) {
        double totalOriginalPrice = 0.0;
        double totalCurrentPrice = 0.0;

        // Calculate the total original price and current price
        for (int i = 0; i < prices.length; i++) {
            totalOriginalPrice += originalWeights[i] * prices[i];
            totalCurrentPrice += weights[i] * prices[i];
        }

        // Calculate the scaling factor
        double scaleFactor = totalOriginalPrice / totalCurrentPrice;

        // Redistribute the weights based on the scaling factor
        for (int i = 0; i < weights.length; i++) {
            weights[i] *= scaleFactor;
        }

        return weights;
    }

</details>


# 答案1
**得分**: 0

以下是翻译好的部分:

"有无限多种方法可以做到这一点。这完全取决于你希望如何分配权重。

例如,你可以决定让你的权重遵循这样的规则:

    权重与Math.exp((price - k)*(price - k))成正比

现在,当`k`趋近于负无穷时,平均价格将趋近于你列表中的底价。给定`k`,你可以轻松计算平均价格应该是多少。当`k`趋近于正无穷时,平均价格将趋近于最高价格。

没有分析方法可以确定`k`应该是多少,但你可以使用类似下面未经测试的代码进行搜索。

    double k0 = 0.0;
    double k1 = 1.0;
    double epsilon = 0.00001;
    while (averagePrice(k1) &lt; desiredPrice) {
        k0 = k1;
        k1 += k1;
    }
    if (desiredPrice &lt; averagePrice(k0)) {
        k0 = -1;
        k1 = 0;
        while (desiredPrice &lt; averagePrice(k0)) {
            k1 = k0;
            k0 -= k0;
        }
    }
    while (k0 + epsilon) {
        kMid = (k0 + k1)/2;
        double averageMid = averagePrice(kMid);
        if (averageMid &lt; desiredPrice) {
            k0 = kMid;
        } else if (desiredPrice &lt; averageMid) {
            k1 = kMid;
        } else {
            return weightsFor(kMid);
        }
    }
    ... 平均权重weightsFor(k0)和weightsFor(k1)以获得所需的平均值

如果你有很多价格相对均匀地分布在你所期望的价格周围,这将给出权重,看起来很像一个正态曲线,接近你所期望的价格。

但你实际上可以选择任何你想要的价格分布形状,相同的思想也会起作用。如果你能够接受改变形状,增大`epsilon`将会加快搜索速度,尽管最终分布可能不如你选择的理想分布完美。"

<details>
<summary>英文:</summary>

There are literally an infinite number of ways to do this.  It all depends on how you want your weights to be distributed.

For example you can decide that your weights have to follow a rule like this:

    weight is proportional to Math.exp((price - k)*(price - k))

Now as `k` goes to - infinity, the average price goes to the bottom price in your list.  Given `k` you can easily calculate what the average price should be.  As `k` goes to + infinity, the average price goes to the top price

There is no analytical way to figure out what `k` should be, but you can easily search with something like this untested code.

    double k0 = 0.0;
    double k1 = 1.0;
    double epsilon = 0.00001;
    while (averagePrice(k1) &lt; desiredPrice) {
        k0 = k1;
        k1 += k1;
    }
    if (desiredPrice &lt; averagePrice(k0)) {
        k0 = -1;
        k1 = 0;
        while (desiredPrice &lt; averagePrice(k0)) {
            k1 = k0;
            k0 -= k0;
        }
    }
    while (k0 + epsilon) {
        kMid = (k0 + k1)/2;
        double averageMid = averagePrice(kMid);
        if (averageMid &lt; desiredPrice) {
            k0 = kMid;
        } else if (desiredPrice &lt; averageMid) {
            k1 = kMid;
        } else {
            return weightsFor(kMid);
        }
    }
    ... average out weightsFor(k0) and weightsFor(k1) to get desiredAverage

If you have a lot of prices fairly evenly distributed around your desired one, this will give weights that look a lot like a normal curve averaging near your desired one.

But you can literally choose any family of shapes that you want for the prices and the same idea will work.  And if you&#39;re tolerant of changing the shape, making `epsilon` larger will cut the search faster at the cost of having the final distribution a little less perfectly the ideal that you chose.

</details>



huangapple
  • 本文由 发表于 2023年3月3日 23:01:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628673.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定