如何通过指数曲线拟合数据(How to fit data by exponential curve)
我的项目有点问题,因为我有一组数据,我绘制它以获得2条曲线,我想用指数曲线拟合这些图。
我看过这篇文章: 在没有初步猜测的情况下拟合指数衰减 。 但我的例子有点不同。
这就是我得到的数据:
我的脚本如下:
mask_G = np.bitwise_and( tbdata['G'] < 99.99, tbdata['GERR'] < 0.2) mask_R = np.bitwise_and( tbdata['R'] < 99.99, tbdata['RERR'] < 0.2) G_corrected = tbdata[mask_G] R_corrected = tbdata[mask_R] fig13 = plt.gcf() fig13.set_size_inches(16, 9) fig13, (ax1,ax2) = plt.subplots(1,2) fig_error_g = ax1.plot(G_corrected['G'], G_corrected['GERR'], '.') ax1.set_xlabel('G') ax1.set_ylabel('GERR') ax1.set_title('Evolution de GERR en fonction de G') fig_error_r = ax2.plot(R_corrected['R'], R_corrected['RERR'], '.') ax2.set_xlabel('R') ax2.set_ylabel('RERR') ax2.set_title('Evolution de RERR en fonction de R') fig13.tight_layout() plt.savefig('graphique.png') plt.show()
我试着写这个,基于scipy doc:
def exponential(x,a,b,c) : return a * np.exp(-b * x) + c xdata = G_corrected['G'] y = G_corrected['GERR'] ydata = y + 0.2 * np.random.normal(size=len(xdata)) popt, pcov = curve_fit(exponential, xdata, ydata)
但我得到:
/home/user/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/scipy/optimize/minpack.py:601:OptimizeWarning:无法估计参数的协方差
类别= OptimizeWarning)你对我如何处理有任何想法吗?
非常感谢 ;)
编辑:
我试着像这样适合我的情节:
mask_G = np.bitwise_and( tbdata['G'] < 99.99, tbdata['GERR'] < 0.2) mask_R = np.bitwise_and( tbdata['R'] < 99.99, tbdata['RERR'] < 0.2) G_corrected = tbdata[mask_G] R_corrected = tbdata[mask_R] params = np.polyfit(G_corrected['G'], np.log(G_corrected['GERR']),1) a = params[0] A = np.exp(params[1]) fig13 = plt.gcf() fig13.set_size_inches(16, 9) fig13, (ax1,ax2) = plt.subplots(1,2) fig_error_g = ax1.plot(G_corrected['G'], (G_corrected['GERR']), '.') fig_error_g = ax1.plot(G_corrected['G'], (A*np.exp(a*G_corrected['G'])),'.') ax1.set_xlabel('G') ax1.set_ylabel('GERR') ax1.set_title('Evolution de GERR en fonction de G') fig_error_r = ax2.plot(R_corrected['R'], np.log(R_corrected['RERR']), '.') ax2.set_xlabel('R') ax2.set_ylabel('RERR') ax2.set_title('Evolution de RERR en fonction de R') fig13.tight_layout() plt.savefig('graphique.png') plt.show()
我得到:
您如何看待结果?
I get a little problem with my project because I have a set of data, I plot it in order to get 2 curves and I would like to fit this plots by an exponential curve.
I watched this post : fitting exponential decay with no initial guessing. But my example is kind different.
This is what I'm getting with data :
My script is as following :
mask_G = np.bitwise_and( tbdata['G'] < 99.99, tbdata['GERR'] < 0.2) mask_R = np.bitwise_and( tbdata['R'] < 99.99, tbdata['RERR'] < 0.2) G_corrected = tbdata[mask_G] R_corrected = tbdata[mask_R] fig13 = plt.gcf() fig13.set_size_inches(16, 9) fig13, (ax1,ax2) = plt.subplots(1,2) fig_error_g = ax1.plot(G_corrected['G'], G_corrected['GERR'], '.') ax1.set_xlabel('G') ax1.set_ylabel('GERR') ax1.set_title('Evolution de GERR en fonction de G') fig_error_r = ax2.plot(R_corrected['R'], R_corrected['RERR'], '.') ax2.set_xlabel('R') ax2.set_ylabel('RERR') ax2.set_title('Evolution de RERR en fonction de R') fig13.tight_layout() plt.savefig('graphique.png') plt.show()
I tried to write that, which based on scipy doc :
def exponential(x,a,b,c) : return a * np.exp(-b * x) + c xdata = G_corrected['G'] y = G_corrected['GERR'] ydata = y + 0.2 * np.random.normal(size=len(xdata)) popt, pcov = curve_fit(exponential, xdata, ydata)
but I get :
/home/user/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/scipy/optimize/minpack.py:601: OptimizeWarning: Covariance of the parameters could not be estimated
category=OptimizeWarning)Do you have any idea on how I can process ?
Thank you so much ;)
EDIT :
I tried to fit my plot like that :
mask_G = np.bitwise_and( tbdata['G'] < 99.99, tbdata['GERR'] < 0.2) mask_R = np.bitwise_and( tbdata['R'] < 99.99, tbdata['RERR'] < 0.2) G_corrected = tbdata[mask_G] R_corrected = tbdata[mask_R] params = np.polyfit(G_corrected['G'], np.log(G_corrected['GERR']),1) a = params[0] A = np.exp(params[1]) fig13 = plt.gcf() fig13.set_size_inches(16, 9) fig13, (ax1,ax2) = plt.subplots(1,2) fig_error_g = ax1.plot(G_corrected['G'], (G_corrected['GERR']), '.') fig_error_g = ax1.plot(G_corrected['G'], (A*np.exp(a*G_corrected['G'])),'.') ax1.set_xlabel('G') ax1.set_ylabel('GERR') ax1.set_title('Evolution de GERR en fonction de G') fig_error_r = ax2.plot(R_corrected['R'], np.log(R_corrected['RERR']), '.') ax2.set_xlabel('R') ax2.set_ylabel('RERR') ax2.set_title('Evolution de RERR en fonction de R') fig13.tight_layout() plt.savefig('graphique.png') plt.show()
and I get :
What do you think about the result ?
原文:https://stackoverflow.com/questions/36834637
最满意答案
这个堆栈溢出的答案我怎样才能播放与Web音频API相反的音频? 显示设置
audio.playbackrate = -1
将工作,除了在基于WebKit的浏览器。 Chrome和Safari会忽略此设置,但其他浏览器可能会支持此设置。一个有趣的事情可能是实施倒带回几秒钟,有点像一些DVR播放器。 像这样的东西可能会工作:
$('button.rewind').click(function() { var currentTime = player.currentTime; player.currentTime = (currentTime >= 3.0) ? currentTime - 3.0 : 0; });
对于特征的对称性,您也可以使用“快进”进行同样的操作。 你的2x按钮是一个很好的“更快播放”的解决方案,这是对这种方法的很好补充。
我为此创建了一个jsFiddle,以及您可能会喜欢的各种其他更改: https ://jsfiddle.net/mgaskill/11n63g3w/
This Stack Overflow answer for How can I play audio in reverse with web audio API? shows that setting the
audio.playbackrate = -1
will work, except in WebKit-based browsers. Chrome and Safari will ignore this setting, although other browsers may support it.An interesting thing to do might be to implement Rewind to go back a few seconds, kind of like it does with some DVR players. Something like this might work:
$('button.rewind').click(function() { var currentTime = player.currentTime; player.currentTime = (currentTime >= 3.0) ? currentTime - 3.0 : 0; });
You could do the same with Fast Forward, as well, for symmetry of the features. Your 2x button is a good "play faster" solution, which is a good complement to this approach.
I have created a jsFiddle for this, with various other changes that you might like: https://jsfiddle.net/mgaskill/11n63g3w/
相关问答
更多-
音频不能在html5中使用(Audio not working in html5)[2022-10-01]
Firefox不支持MP3。 它不会显示回退消息,因为它支持音频标签。 https://developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements#MPEG_H.264_(AAC_or_MP3) Firefox doesn't support MP3. It won't show the fallback message because it supports the audio tag. https:// ... -
这个堆栈溢出的答案我怎样才能播放与Web音频API相反的音频? 显示设置audio.playbackrate = -1将工作,除了在基于WebKit的浏览器。 Chrome和Safari会忽略此设置,但其他浏览器可能会支持此设置。 一个有趣的事情可能是实施倒带回几秒钟,有点像一些DVR播放器。 像这样的东西可能会工作: $('button.rewind').click(function() { var currentTime = player.currentTime; player.curr ...
-
HTML5 audio playbackRate属性不适用于移动浏览器?(HTML5 audio playbackRate property is not working for mobile browser?)[2021-07-27]
没有任何进一步上下文的可能猜测是移动浏览器根本不支持HTMLMediaElement接口 。 The likely guesstimate without any further context is that the mobile browser simply doesn't support the HTMLMediaElement interface. -
WebAudio:Oscillating AudioBufferSource playbackRate(WebAudio: Oscillating AudioBufferSource playbackRate)[2021-12-22]
不,你没有做错任何事。 Blink有一个我们不支持这个的错误,上周刚被别人报告给我,我提交了: https : //code.google.com/p/chromium/issues/detail?id = 311284 。 我们将解决这个问题。 与此同时,使用LFO在延迟节点的delayTime上驱动振荡对任何音频连接(不仅仅是缓冲源节点)进行颤音效果实际上相对容易 - 检查我添加到http结尾的“Vibrato”效果: //webaudiodemos.appspot.com/input/index.ht ... -
在媒体项上调用.play()或.play()将(可能)重置.playbackRate 。 之后设置.playbackRate ,或者使用.defaultPlaybackRate 。 这是一个小提琴,表明: audio = document.createElement('audio'); audio.src = 'http://www.html5rocks.com/en/tutorials/audio/quick/test.ogg'; audio.addEventListener("canplay", fun ...
-
音频波没有负值(Audio wave has no negative values)[2023-05-17]
我认为关键问题是你试图将大数字放入一个小空间。 也就是说,如果没有首先将原始数字缩放到适合char存储的大小,则会截断int数据中的一些信息,导致大的负值被解释为零。 顺便说一下,如果你的任何负值都是-128,我认为这个表达式: (char) ( (unsigned)dif & 0xff)会返回负值。 我仍然不确定你首先使用该表达式究竟是做什么的,即如果你已经从规范化函数中获得了一个缩放数据值(假设它有效),那么你不会把它放到你的文件中吗? 在任何情况下,我可以告诉你,你正在努力完成两件事,规范化(在这里, ... -
检查playbackRate是否被识别: 'playbackRate' in document.createElement('audio'); 根据developer.mozilla.org ,不支持以下属性: 移动Chrome(Android) IE Mobile Opera Mobile Check if playbackRate is recognized: 'playbackRate' in document.createElement('audio'); According to develo ...
-
几个星期前发现它,当我打电话时声音没有满载。 found it couple of weeks ago, the sounds wasnt fully loaded when i called it.
-
第一个div和音频标签ID相同="player" 。 因此,当我将其更改为"playe"更改第1 div id 。 如果您希望音频标签具有id="player" 。 现在这将有效。
相关文章
更多- Spring Data: a new perspective of data operations
- data-config
- (二)solr data import
- 《Big Data Glossary》笔记
- Spring Data Solr教程(翻译)
- 使用Solr Data Import的delta-import功能
- TMF大数据分析指南 Unleashing Business Value in Big Data(一)
- Solr4:配置Data Import,从数据库直接创建索引
- The Log: What every software engineer should know about real-time data's unifying abstraction
- 《数据结构与STL》(Data Structures and the Standard Template Library)扫描版[PDF]
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)