首页 \ 问答 \ 数值模式匹配(Numerical Pattern Matching)

数值模式匹配(Numerical Pattern Matching)

我正在研究的项目需要一些数字模式匹配。 我的搜索没有发现许多相关的点击,因为大多数结果往往是围绕文本模式匹配。 我们的想法是,我们需要注意某些波形模式,并尝试将输入数据与我们将要构建的波形数据库进行匹配。 这是我们需要匹配的一种波形的示例。

alt text http://tmp.stayhealthy.com/wave.png

那里有一个明显的模式,但峰值不会有完全相同的值,但波次迭代的整体形状将非常相似。 有没有人对如何存储和以后匹配这些模式和/或其他搜索术语有任何建议,我可以用它来找到关于模式匹配主题的更多信息?

蒂姆,谢谢。


A project I'm researching requires some numerical pattern matching. My searches haven't turned up many relevant hits since most results tend to be around text pattern matching. The idea is we'll have certain wave patterns we'll need to be watching for and trying to match incoming data vs the wave database we will be building. Here is and example of one of the wave patterns we'll need to be matching against.

alt text http://tmp.stayhealthy.com/wave.png

There is clearly a pattern there, but the peaks will not have the exact same values, but the overall shape of the wave iterations will be very similar. Does anyone have any advice on how to go about storing and later matching these patterns, and / or other search terms I can use to find more information on the subject of pattern matching?

Thanks, Tim.


原文:https://stackoverflow.com/questions/2669470
更新时间:2024-01-08 06:01

最满意答案

如果您担心做某事的成本,那就去衡量一下。 如果你无法衡量差异,那么差异可能无关紧要(如果重要的话,你就可以衡量它)。

要回答更具体的问题,变量没有任何内在成本。 在CPU上实际执行的代码中不存在变量。 它们是源级构造,并且编译器没有义务在源代码变量之间创建某种一对一映射,例如,执行push指令,或使用的寄存器或其他任何东西。 代码中的单个变量可以对应于使用多个不同的寄存器(编译器可能会选择不时地移动它),或者几个不同的变量可能最终共享同一个寄存器,因为它们从未在同时。

编译器所做的许多事情之一是确定变量的生命周期。 何时首次使用,何时使用? 当你声明它或它超出范围时,无关紧要。

编译器通常使用的转换将您的代码放入更适合优化的形式,即将每个赋值转换为一个新的,唯一的变量,基本上与第二个示例类似。 这就是编译器喜欢使用代码的方式,因为现在它可以清楚地看到依赖关系。 在第一种情况下,看起来整个函数中必须存在相同的变量,并且可以重用这两个操作。 在第二种情况下,我们可以很容易地看到它们是独立的,独立的变量,并且我们可以看到它们的生命周期不重叠(在声明rateNode之后不使用rateNode )。

两个版本都可能生成完全相同的代码,但第二个版本更接近于优化编译器内部对代码所做的操作。


If you're worried about the cost of doing something, then measure it. If you can't measure a difference, then the difference can not possibly matter (if it mattered, you'd be able to measure it).

To answer your more specific question, a variable does not have any intrinsic cost. Variables do not exist in the code that is actually executed on the CPU. They are a source-level construct, and the compiler is not obliged to create some kind of 1-to-1 mapping between source code variables and, say, push instructions executed, or registers used, or anything else. A single variable in your code can correspond to the use of several different registers (the compiler might choose to move it around from time to time), or several different variables might all end up sharing the same register because they're never used at the same time.

One of the many things a compiler does is determine the lifetime of a variable. When is it first used, and when is it last used? It doesn't matter when you declared it, or when it goes out of scope.

A transformation commonly used by compilers to put your code into a form more amenable to optimizations is to turn every assignment into a new, unique, variable, basically like in your second example. That's how the compiler prefers to work with the code, because now it can see the dependencies clearly. In the first case, it looks as if the same variable has to exist throughout the function, and be reused for both operations. In the second case, we can easily see that they're separate, independent, variables, and we can see that their lifetimes do not overlap (idNode is not used after the declaration of rateNode).

Both versions will likely produce the exact same code, but the second version is closer to what optimizing compilers do to the code internally.

相关问答

更多
  • 什么是“可变范围”? 变量具有有限的“范围”或“可访问的地方”。 只是因为你写了$foo = 'bar'; 一旦你的应用程序的某个地方并不意味着您可以从应用程序内的其他地方引用$foo 。 变量$foo具有一定的范围,在该范围内它是有效的,只有相同范围内的代码才能访问该变量。 PHP中定义的范围如何? 很简单:PHP具有函数范围 。 这是PHP中唯一存在的范围分隔符。 函数内的变量只能在该函数内部使用。 功能之外的变量可以在函数之外的任何地方使用,但不在任何函数内。 这意味着PHP中有一个特殊的范围: 全局 ...
  • 8.3.2参考文献§4 未指定参考是否需要存储 也就是说,如果引用需要存储,它通常需要与指针一样多的存储空间: struct P { int* p; }; struct R { int& r; }; static_assert(sizeof(P) == sizeof(R), "sizeof(P) == sizeof(R)"); 8.3.2 References §4 It is unspecified whether or not a reference requires storag ...
  • 我认为你想要做的是传递对象引用 var obj = { var: 'initial' }; var a = [{ test: 'old', new: 'no' }, { test: obj, new: 'yes' }]; var o = { test: obj, new: 'yes' }; obj.var = 'objModified'; alert(o.test.var); // Changes correctly obj.var = 'arrModified'; alert(o.test.var ...
  • 我可以想象几种方法: 一些代码像 sysuse auto, clear quietly ds local myvar `:word 5 of `r(varlist)'' display "`myvar'" 会让你在不知道名字的情况下使用第五个变量。 您可以使用循环并以这种方式定义变量列表。 这基本上是http://www.stata.com/statalist/archive/2010-03/msg00073.html的回应。 将您的数 ...
  • 这将被称为“动态部分” - 您可以在Handlebars文档中查看。 可以通过使用子表达式语法来动态选择要执行的部分。 {{> (whichPartial) }}将评估whichPartial,然后呈现此函数返回其名称的部分。 子表达式不能解析变量,因此哪些部分必须是函数。 如果一个简单变量具有部分名称,则可以通过查找帮助程序解析它。 {{> (lookup . 'myVariable') }} This would be called "dynamic partial" – you can check h ...
  • 如果使用&$foo通过引用显式传递变量,则只通过引用(在当前版本的PHP中)传递变量。 同样,在将变量声明为新变量(例如$foo = $bar ,$ foo将是对$ bar的引用,直到值发生变化。 然后它是一个新的副本。 这里有很多检测参考的方法,也许可以检查一些参考 。 (为什么你需要这样做是未知的,但它仍然存在)。 http://www.php.net/manual/en/language.references.spot.php A variable is only passed by referenc ...
  • “引用”(变量别名)使您的代码更难理解,并且可能成为难以理解的错误的来源。 没有正当理由在php中使用引用并且在更安全的一方尝试完全避免它们。 不,php5中的对象与“引用”无关。 在PHP中实现的“引用”是一个奇怪的概念。 通常,在编程语言中,变量彼此独立,因此更改一个变量不会影响其他变量。 Php“引用”允许多个变量共享相同的值并且彼此依赖。 基本上,你改变了一个变量,而你认为完全不相关的另一个变量也会发生变化。 这不是好事,经常导致很多混乱。 php中的对象(我需要添加'five'?)与上述意义上的“ ...
  • 如果您担心做某事的成本,那就去衡量一下。 如果你无法衡量差异,那么差异可能无关紧要(如果重要的话,你就可以衡量它)。 要回答更具体的问题,变量没有任何内在成本。 在CPU上实际执行的代码中不存在变量。 它们是源级构造,并且编译器没有义务在源代码变量之间创建某种一对一映射,例如,执行push指令,或使用的寄存器或其他任何东西。 代码中的单个变量可以对应于使用多个不同的寄存器(编译器可能会选择不时地移动它),或者几个不同的变量可能最终共享同一个寄存器,因为它们从未在同时。 编译器所做的许多事情之一是确定变量的生 ...
  • 你必须复制你的表格。 You'll have to make a copy of your table.
  • 它只是糟糕的编程! 假设你已经完成了你的程序,然后一个月后你想回来添加其他功能。 但是你意外地在新类中的全局变量中使用了它。 现在它改变了你不想改变的其他类中的东西。 你有更多的错误,你不知道从哪里开始,因为你没有触摸代码一个月。 关于ref词还有一件事 - 它的目标之一是在返回变量之前强制初始化变量。 这样编译器确保你不使用包含垃圾的变量来破坏代码。 当您使用全局变量时,您可以在该未初始化的全局变量中使用,并且您将获得异常。 因此,如果你知道何时以及如何使用ref和out - 使用它们。 并且不要使用全局 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。