如何产生拉伸图的X值? [英] How to produce X values of a stretched graph?

查看:112
本文介绍了如何产生拉伸图的X值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的意思是,我需要每日记录数据并检查数据每个月对数据在另一个月。



唯一的问题是有些月份比其他月份长。所以我想出了一个我想要做到这一点的方法,但我对如何做到这一点感到困惑......



基本上,我正在看这个网站: http://paulbourke.net/miscellaneous/interpolation/ 并尝试着将每组坐标转化为一个具有31个X和Y值的图形(我想使用余弦内插器,但我仍然试图找出如何处理它)。



现在,X值有一个函数。我可以传入类似(1..28)的东西,并将它变成31个值...足够简单的代码,像这样的东西适用于我:

  def total =(1..30)
defday = 28

def resize = {x,y->
result = []
x.each {result<< (it *(y / x.size())}
返回结果
}

resize(total,days)

其中返回一个包含从0到28的31个Y值列表。



我的问题是:我如何将相应的Y值列表转换为这些值?我真的很难将这个概念包裹起来,并且可以使用一些帮助。



我的第一个想法是简单地通过这个函数运行Y值,但是返回的值都低于原始输入。



我在寻找对于某些可以在某些点保留值的东西,只是简单地将图拉伸出来。

长度,该值需要与原始图长(1/3)相同。



任何人都可以帮我解决这个问题吗?我很难过。



预先感谢!

解决方案

我认为你的算法是正确的,你只需要正常化x轴。



我想出了这段代码(以及一些图)来证明我相信是答案。

定义一些x和y值:

  def x = 1..30 
def y = [ 1..15,15..1] .flatten()

然后,生成xy列表值的格式为: [[x,y],[x,y],...

  def xy = [x,y] .transpose()

我们绘制这个列表,我们得到:





然后定义一个标准化函数(基本上和你的一样,但它不会触及y值)

  def normalize(xylist,days){
xylist.collect {x,y - > [x *(days / xylist.size()),y]}
}

然后,我们可以将我们的列表标准化为28天

  def normalxy = normalize(xy,28)


$ b现在,如果我们绘制这些点,我们得到



正如你所看到的,两块地块的形状相同,只是宽度不同......

I'm trying to "normalize" monthly data in a way.

What I mean by that is, I need to take daily values and check the data from each month against the data in another month.

The only problem with this is that some months are longer than others. So I have come up with a way that I want to do this, but I'm kind of confused as to exactly how to do it...

Basically, I'm looking at this website: http://paulbourke.net/miscellaneous/interpolation/ and trying to transform each set of coordinates into a graph with 31 X- and Y-values (I would like to use the Cosine interpolator, but I'm still trying to figure out what to do with it).

Now, the X values have a function. I can pass in something like (1..28) and morph it into 31 values...simple enough code, something like this works for me:

def total = (1..30)
def days = 28

def resize = {x, y->
    result = []
    x.each{ result << (it * (y/x.size())}
    return result
}

resize(total,days)

Which returns a list of 31 Y-values spanning from 0 to 28.

My question is: How do I translate a list of the corresponding Y values to these values? I'm having a really hard time wrapping my head around the concept and could use a little help.

My first thought was to simply run the Y-values through this function too, but that returns values that are all lower than the original input.

I'm looking for something that will retain the values at certain points, but simply stretch the graph out horizontally.

For example, at the x value at (1/3) of the graph's length, the value needs to be the same as it would be at (1/3) of the original graph's length.

Can anyone help me out on this? It's got me stumped.

Thanks in advance!

解决方案

Not sure where the problem lies with this, so I made up some data

I think your algorithm is correct, and you only need to normalize the x-axis.

I came up with this code (and some plots) to demonstrate what I believe is the answer

Define some x and y values:

def x = 1..30
def y = [1..15,15..1].flatten()

Then, generate a list of xy values in the form: [ [ x, y ], [ x, y ], ...

def xy = [x,y].transpose()

If we plot this list, we get:

Then define a normalize function (basically the same as yours, but it doesn't touch the y value)

def normalize( xylist, days ) {
  xylist.collect { x, y -> [ x * ( days / xylist.size() ), y ] }
}

Then we can normalize our list to 28 days

def normalxy = normalize( xy, 28 )

Now, if we plot these points, we get

As you can see, both plots have the same shape, they are just different widths...

Have I missed the point?

这篇关于如何产生拉伸图的X值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆