tag:blogger.com,1999:blog-20697542026713174582024年09月28日T10:44:22.210+10:00cbradBrad Clow's blogUnknownnoreply@blogger.comBlogger184125tag:blogger.com,1999:blog-2069754202671317458.post-92218189347210294612015年08月07日T11:23:00.001+10:002015年08月07日T11:23:52.751+10:00NinjaTrader 7 Max Drawdown Percent Is Not What You Think It IsMaximum Drawdown is a common metric used in evaluating trading systems. It is <a href="http://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp">defined&nbsp;</a> as the largest equity peak to trough percentage loss.<br /><br /><a href="http://ninjatrader.com/">NinjaTrader</a> 7 includes a Strategy Analyzer for backtesting trading systems. The Max. Drawdown Percent value in the summary statistics is very different to the definition.<br /><br />The Strategy Analyzer has no starting account size. Therefore by definition there can't a be maximum drawdown %. For example, if the largest drawdown in profits occurs immediately, the maximum drawdown % would be undefined due to dividing by zero.<br /><br />Another consequence of no initial account size is that there is no equity curve. The closest thing is a graph of cumulative profit.<br /><br />The maximum drawdown % value reported by the Strategy Analyzer appears to be the sum of percentage gains/losses for all the individual trades involved in the maximum cumulative profit drawdown. I can not think of any practical use for this number.<br /><br />References. See the support articles <a href="http://ninjatrader.com/support/forum/showthread.php?t=38295">here </a>and <a href="http://ninjatrader.com/support/forum/showthread.php?t=32504">here</a>.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-85899309787501163922014年11月04日T12:27:00.002+10:002014年11月04日T12:27:55.167+10:00Daylight Savings And International Markets In Investor/RTAfter my <a href="http://bradclow.blogspot.com.au/2014/10/poor-experience-with-acme-market.html">poor experience</a> with Acme Market Analytics I am investigating <a href="http://www.linnsoft.com/">Investor/RT</a>&nbsp;as an alternative. I ran into a problem with session management here to, however unlike Rancho Dinero, support has been excellent.<br /> <h3> The Problem</h3> When the exchange time zone finishes daylight savings time (DST), but your local time zone doesn't change and before New York DST finishes your charts will be incorrect. I am using <a href="http://www.iqfeed.net/">IQFeed </a>as my data provider.<br /> <br /> I am located in Brisbane, Australia and we have no DST. I trade the German DAX in the evenings and they finished DST about one week ago on Sunday, October 26. So from my perspective, last week the <a href="http://www.eurexchange.com/">Eurex </a>DAX futures market shifted an hour later to open at 17:00 Brisbane time. In Investor/RT this had the effect of leaving an empty gap of one hour from 16:00 and missing the last hour of trade.<br /> <h3> The Solution</h3> In Investor/RT session start and end times are specified in the local PC time zone. This is how Investor/RT is designed and so it cannot automatically handle this situation as it has no record of the exchange's time zone.<br /> <br /> The only solution that should apparently work seamlessly through international DST changes is to set my Windows time zone to New York. I am not sure how specific the solution is to using IQFeed.<br /> <h3> Customer Service</h3> Support was excellent. They operate in US hours, but did respond sometimes after their normal business hours finished. They were also very open about current product design, limitations and how it could be improved in the future.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-48964717630925363862014年10月14日T13:30:00.002+10:002014年10月14日T13:30:41.011+10:00Poor Experience With Acme Market AnalyticsThis is my first post about trading financial markets. I would rather have not written it. Unfortunately I haven't been able to resolve a product issue and I found the customer service disappointing. So maybe someone else can help me or maybe this post will help others when evaluating these products.<br /> <h3> The Product Problem</h3> Acme Market Analytics by <a href="http://www.ranchodinero.com/">Rancho Dinero</a> is a suite of indicators for <a href="http://www.ninjatrader.com/">NinjaTrader</a>. It has a comprehensive set of features, satisfying most of my current requirements. They have put a lot of effort into the design and these are easily the most elegant and attractive NinjaTrader indicators I have seen.<br /> <br /> One key part of the product suite is the <a href="http://www.ranchodinero.com/acme-studies/acme-volume-profile/">Acme Volume Profile</a>&nbsp;that includes a feature to&nbsp;split exchange sessions into RTH and ETH profiles. I have set these up for various markets and recently attempted to do so for the <a href="http://www.asx.com.au/products/index-derivatives/asx-index-futures-contract-specifications.htm#spi_futures">ASX SPI 200 Index Futures</a>. This resulted in a strange situation where most days worked fine, except Mondays. It created an extra, small profile just for the first bar of Monday RTH.<br /> <br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC2TDnlwJB3eMDaEp9vJ88agAAi8BGsfNjQcclln7r3EBdQQ1lIi7twDHChqG1iswXC7uGoVypoTmOU9WHiVTCFsV2cWIeZXd6cfdEBqE0Y4SjQ4y_cF0Wqq_-JdqZwvMs9snVMqPy254/s1600/SPI+12-14+(15%2BMin)%2B%2B7_10_2014.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC2TDnlwJB3eMDaEp9vJ88agAAi8BGsfNjQcclln7r3EBdQQ1lIi7twDHChqG1iswXC7uGoVypoTmOU9WHiVTCFsV2cWIeZXd6cfdEBqE0Y4SjQ4y_cF0Wqq_-JdqZwvMs9snVMqPy254/s1600/SPI+12-14+(15%2BMin)%2B%2B7_10_2014.jpg" height="553" width="640" /></a></div> <br /> My NinjaTrader sessions are configured as follows.<br /> <br /> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihlUxni3wsa7EVuNcIXAbFOAa8qeKYJlElssqK-SgAKHJhZAGnhAuhYRa9hjK2IJf14m59B2qflmf8R_Uk_tunTWs0mzopMYR827_EXtzFwPCAMzbMnuAz8Wfm9tThWz-w22BhWvROVxw/s1600/SPI+RTH+Session.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihlUxni3wsa7EVuNcIXAbFOAa8qeKYJlElssqK-SgAKHJhZAGnhAuhYRa9hjK2IJf14m59B2qflmf8R_Uk_tunTWs0mzopMYR827_EXtzFwPCAMzbMnuAz8Wfm9tThWz-w22BhWvROVxw/s1600/SPI+RTH+Session.png" height="180" width="320" /></a></div> <div class="separator" style="clear: both; text-align: center;"> RTH</div> <div class="separator" style="clear: both; text-align: center;"> <br /></div> <div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2GQVBffzUmBWr4aojH3uRs9uu9ayl2wy8ChKPQCqs4jb25-kplj5hvN57kOkKY4ewbsYojjWrrMXwvqmRNnrYY2UL716HBHmgzFwwxflYD8ipyxqgRoejQ_DGglgj2C9yt4DZFOZihzA/s1600/SPI+ETH+Session.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2GQVBffzUmBWr4aojH3uRs9uu9ayl2wy8ChKPQCqs4jb25-kplj5hvN57kOkKY4ewbsYojjWrrMXwvqmRNnrYY2UL716HBHmgzFwwxflYD8ipyxqgRoejQ_DGglgj2C9yt4DZFOZihzA/s1600/SPI+ETH+Session.png" height="178" width="320" /></a></div> <div class="separator" style="clear: both; text-align: center;"> ETH</div> <div class="separator" style="clear: both; text-align: left;"> <br /></div> <div class="separator" style="clear: both; text-align: left;"> The reason the RTH sessions start at 09:45 is the first print seems to happen in the minute of 09:49, before the publicised open at 09:50. Even if I set the start times to 09:50 the problem still occurs.</div> <h3> The Customer Service Problem</h3> It takes a few days to get through the usual customer service 101 kinds of things. Support recommends session template changes, advises on reloading historical data, etc. I am in Australia, support operates in US hours so communication is slow due to the timezone differences.<br /> <br /> I am only new to this market and discover that Pre Open seems to start in the minute before the publicised open at 09:50. Some confusion ensues on my behalf while I am figuring out what is going on.<br /> <br /> I end up mitigating this situation by starting the RTH sessions five minutes earlier and write a detailed email to support about this, how I've tried their suggestions and it still doesn't work.<br /> <br /> This is where things start to deteriorate. Support throws their hands in the air and says they have no more suggestions, it must be a problem with the exchange.<br /> <br /> We go back and forwards a few more times. No solution. I ask for my money back, they refuse.<br /> <br /> Not once through this process did support indicate they actually tried to get this working themselves. In general a complete lack of interest in going above and beyond for customer satisfaction. I don't wish to deal with this kind of "support" further, so time to start looking for an alternative platform/product.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-63985428925002358002013年06月22日T20:43:00.001+10:002013年06月22日T20:43:55.516+10:00Ripping Blu-rays for Mac OSX, the WD TV Live and everything elseI rip my Blu-rays to play on our WD TV Live (firmware 1.06.43_V), Macs and mobile devices (iPad, iPod, Samsung Galaxy Note II). There have been many issues over the last few years, with subtitles being the last one to solve.<br /> <br /> I keep uncompressed mkv files to play on the WD TV Live (and as master copies) and transcode to m4v for all the other devices.<br /> <ol> <li>Rip with <a href="http://www.makemkv.com/">Makemkv</a>. I use an external Blu-ray drive on a MacBook Pro. Make sure all english subtitle tracks (forced only) are selected.&nbsp;<a href="http://www.videolan.org/vlc/index.html">VLC</a>&nbsp;(2.0.6) plays subtitles correctly but the WD TV Live doesn't.</li> <li>Remux the mkv with <a href="http://www.bunkus.org/videotools/mkvtoolnix/">MKVToolNix</a>&nbsp;using&nbsp;the&nbsp;default settings - <a href="http://www.makemkv.com/forum2/viewtopic.php?f=1&amp;t=4944">fixes</a> the WD TV Live subtitles issue.&nbsp;</li> <li>Transcode with <a href="http://handbrake.fr/">Handbrake</a> (0.9.9 x86_64). Use the iPad profile and on the Subtitles tab select Foreign Audio Search, Forced Only, Burned In.</li> </ol> <div> Working well so far. Can't wait for a decent broadband network and an up to date movie/tv content streaming service in Australia!</div> <br /> <br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-58371100739499074462010年11月24日T10:41:00.000+10:002010年11月24日T10:42:53.520+10:00DivvyContinuing on from my <a href="http://bradclow.blogspot.com/2010/11/optimal-layout.html">post</a> about <a href="http://most-advantageous.com/optimal-layout/">Optimal Layout</a> I also tried out <a href="http://www.mizage.com/divvy/">Divvy</a> (version 1.2.3) for more efficient window management on Mac OS X. My work setup is a MacBook Pro with an external display and Spaces enabled. An important goal is to achieve keyboard only window control.<br /><br />Divvy is a very simple app. It essentially enables you to divide the screen up into a virtual grid and snap the current window to a region within that grid. The other major feature is the ability to assign keyboard shortcuts to particular regions, enabling you to position and size the current window to one of your predefined regions with ease. There is also an option to use the keyboard shortcuts to move the current window to another display, which I find quite useful.<br /><br />To tile all the windows on the screen in a particular layout requires shifting the focus to each window to position and size it. If your Divvy shortcuts correspond to where you want the windows than this whole process can be done fairly quickly, without touching the mouse/trackpad. Having said that, I would love to define a layout on the Divvy grid and with a keyboard shortcut arrange all windows on the current screen into that layout.<br /><br />I have Windows XP running in a Parallels VM in <a href="http://kb.parallels.com/4670">Coherence</a> mode and Divvy does not seem to work with the Windows windows. Some applications (such as Activity Monitor) also have restrictions on window size that Divvy can't change.<br /><br />Over the days I was trialling Divvy on my work MacBook Pro, I found myself missing it on the Mac at home. For USD14ドル and a license that supports use on multiple Mac's, it is good value.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-2069754202671317458.post-76555547389852025782010年11月23日T10:35:00.000+10:002010年11月23日T13:42:06.848+10:00Optimal LayoutInspired by <a href="http://xmonad.org/">xmonad</a> on linux, I tried out <a href="http://most-advantageous.com/optimal-layout/">Optimal Layout</a> (version 1.1.2) for more efficient window management on Mac OS X. My work setup is a MacBook Pro with an external display and Spaces enabled. An important goal is to achieve keyboard only window control.<br /><br />In Optimal Layout, tiling windows in an arrangement requires<br /><ol><li>explicitly selecting the windows in the Optimal Layout UI</li><br /><li>selecting a layout from a list</li><br /><li>selecting the target display</li></ol><br />My most common use case is to arrange windows in the current space on the display with the focus, i.e. my current context. There are too many steps for this to feel efficient.<br /><br />The available window layouts are predefined, including the window sizing. After arranging windows, sizing adjustments can be made using the sticky resizing feature, but this requires using the mouse. Furthermore, should you open one more window, you have to go through the whole process again.<br /><br />I am disapointed with Optimal Layout and am trying out <a href="http://www.mizage.com/divvy/">Divvy</a>, which I will post about next.Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-2069754202671317458.post-38980298210125969962010年10月28日T11:02:00.001+10:002010年10月28日T11:06:30.410+10:00Installing XMonad on Ubuntu 10.10 Maverick MeerkatI installed <a href="http://ubuntu.com/">Ubuntu</a> 10.10 Maverick Meerkat (in Parallels on my Mac) to try out <a href="http://xmonad.org/">XMonad</a>, the tiling window manager. XMonad is a candidate if I move off the Mac. I am slowly increasing my keyboard use and relying less on the mouse and XMonad is a further step in that direction.<br /><br />I have never installed or used Xmonad before and after too much time stuffing around with the usual linux problems, these are the steps I followed to get a simple, initial installation working on a fresh install of Ubuntu.<br /><br /><ol><li>Install <a href="http://haskell.org/">Haskell</a>, XMonad and <a href="http://en.wikipedia.org/wiki/Dmenu">dmenu</a>.<br /><pre>$ sudo apt-get install haskell-platform xmonad dwm-tools</pre><br />Originally, I installed Haskell and then tried to install XMonad via <a href="http://haskell.org/cabal/">Cabal</a>. Unfortunately the xmonad-contrib package failed to install due to dependency issues.</li><br /><li>Set XMonad to be the window manager for Gnome.<br /><pre>$ gconftool-2 -s /desktop/gnome/session/required_components/windowmanager xmonad --type string</pre><br />Found this at <a href="http://haskell.org/haskellwiki/Xmonad/Using_xmonad_in_Gnome">Xmonad/Using xmonad in Gnome</a>. Don't log out or restart X now. If you do, you will find XMonad workspace 1 broken. It seems to consist of two Gnome panels tiled to fill the screen but hidden behind the desktop and any further windows you create are also hidden. The next step fixes this.</li><br /><li>Create a simple Xmonad configuration file.<br /><pre>$ mkdir ~/.xmonad<br />$ touch ~/.xmonad/xmonad.hs</pre><br />Set the contents of <code>xmonad.hs</code> to<br /><pre class="brush: plain;">import XMonad<br />import XMonad.Hooks.ManageDocks<br /><br />main = xmonad $ defaultConfig {<br /> manageHook = manageDocks <+> manageHook defaultConfig,<br /> layoutHook = avoidStruts $ layoutHook defaultConfig<br /> }</pre><br />Apply the configuration.<br /><pre>$ xmonad --recompile</pre><br />This configuration was found at <a href="http://haskell.org/haskellwiki/Xmonad/Config_archive/John_Goerzen's_Configuration">Xmonad/Config archive/John Goerzen's Configuration</a>.<br /></li><br /><li>Logout and back in again. You should see a standard looking Ubuntu desktop with the menubar across the top and the normal panel along the bottom. See the <a href="http://xmonad.org/tour.html">tour</a> to get started with the XMonad commands.</li></ol>Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-2069754202671317458.post-53913299855516402892010年10月19日T08:00:00.000+10:002010年10月19日T08:38:18.191+10:00Defamation?Yesterday I received a letter from lawyers representing a doctor named in my post <a href="http://bradclow.blogspot.com/2009/03/tonys-letter-to-medical-board-of.html">Tony's letter to the Medical Board of Queensland</a>. They claim the letter contains defamatory statements and demanded I remove the post.<br /><br />At the time I posted this blog entry, Tony was missing and left a public message of possible self harm. People were looking for him, his family was worried and many people in the programming communities Tony frequented online feared for his safety. I published Tony's letter at that time for those people online that had seen and were discussing his message, but had no awareness of the real situation.<br /><br />I do not wish to remove the blog post as it captures a small part of the prolonged trauma Tony endured in engaging with the medical system. I have no reason to doubt that all the practitioners Tony saw genuinely believed they were doing the right thing. This does not change the experience of the patient though. It can be a demoralising cycle of slowly progressing from generalists to specialists, booking appointments weeks/months into the future meanwhile enduring symptoms, bearing the financial burden, deciphering sometimes poor communication, having to evaluate practitioners and their advice and decide next steps in the face of enduring pain.<br /><br />I am disappointed that one of the doctor's involved has resorted to this level of legal involvement against me. Instead of attempting to censor, he could have simply written a rebuttal. I defy anyone that claims the medical system (as a whole) handled Tony's case well. Therefore there is room for improvement that is better served by reflection and constructive criticism rather than a legal approach.<br /><br />I am not a lawyer and have no experience with defamation law. I have removed the doctor's name from the blot post in an attempt to avoid legal confrontation.Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-2069754202671317458.post-91573625285902005292010年10月04日T08:00:00.001+10:002010年10月04日T09:37:03.383+10:00Why are helmets mandatory for cycling?The issue of mandatory helmet laws for cycling has been growing in public awareness. This is possibly due to recent <a href="http://freedomcyclist.blogspot.com/2010/03/criminal-conviction-quashed.html">court cases</a> and <a href="http://www.heraldsun.com.au/news/national/scrap-bike-helmets-associate-professor-chris-rissel-from-sydney-university/story-e6frf7l6-1225906004560">research</a>, the proported lack of take up of the <a href="http://www.melbournebikeshare.com.au/">Melbourne Bike Share</a> and the brand new <a href="http://www.citycycle.com.au/"> Brisbane CityCycle</a> program. <br /><br />Proponents of repealing mandatory helmet laws generally focus their discussion on practical issues. They cite the lack of compelling scientific research regarding helmet efficacy in preventing serious brain injury, the deteriorating overall physical health of society and improving sustainability through lower impact on the environment. My question is should they be required to do that? <br /><br />Supposedly Australia is a free, civilised country. We value our individual freedom. This freedom includes daily choices concerning how our own actions affect our own good, balancing our own personal risk against convenience, benefit and enjoyment. We make these choices whenever we drive our cars, fly in an aeroplane, jump out of an aeroplane, take up smoking, drink varying volumes of alcohol and go swimming.<br /><br />By definition mandatory helmet laws restrict individual freedom. The cyclist is unable to make the choice of balancing personal risk against convenience, benefit and enjoyment. It does not matter what type of bike is being ridden, the speeds, riding surface, distance travelled and presence or absence of vehicles.<br /><br />So my question is why isn't the government required to justify the presence of mandatory helmet laws, since they are exercising power over individual freedom, against some people's will? Such a justification would necessarily be in terms of preventing harm to others, otherwise it impinges on the individual freedom we as a society also claim to value. If no such reasonable justification is available then repealing the laws is the sensible and rational course of action to take.Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-2069754202671317458.post-39267198670285468712010年09月19日T08:41:00.003+10:002010年09月19日T08:49:21.234+10:00QOTD<blockquote>I consider it extremely important–perhaps vital, even–to spend time engaging others intelligently who have diverging views from one’s own. I think that this is, on the whole, one of the most valuable uses of one’s time that exists. Whether it’s consulting a disagreeable book or a person, somehow at the intersection of intelligence and difference lies a "something" that is mind-expanding.</blockquote><br /><a href="http://sealedabstract.com/rants/why-i-stopped-reading-hn/">From Sealed Abstract - Why I stopped reading HN</a> via <a href="http://twitter.com/conal">@conal</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-72798850197268366712010年09月16日T12:18:00.007+10:002010年09月16日T12:26:57.408+10:00Single exponential smoothing and foldlRecently I looked at simple techniques for <a href="http://en.wikipedia.org/wiki/Time_series">time series</a> smoothing and forecasting. One such primitive method is the <a href="http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc431.htm">single exponentially weighted moving average</a> (SEWMA), defined as<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsbZMP6UXbscH3L5KI315lIif9bks4jGsSQjnrRDfhaly6aXkr5YYnkd5wK_cViHWV19Ybi7hypt5zCG-Hv4YmF26zWfENahW9VBioS-BZ21xTnJyY2g_nhP6vTckpwwf9L_7uBPG0_W8/s800/sewma.gif" alt="\begin{align*}<br />S_{t+1} & = \alpha y_t + \left(1-\alpha \right ) S_t \quad \quad 0 \leq \alpha \leq 1 \quad \quad t \geq 2 \\<br />S_2 & = y_1<br />\end{align*}"/><br /><br />where the sequences are indexed from 1. <img class="latex-inline" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIxOwrUsMUgPEr2P546UPN3oQ2uf_OzICP5lgDELl6ZNvne0fyrKhLRJWFK-GSJ79fUavn7kt1WzTeYCLVuLscu4_SAVakll48wGiS2m7M8QL-XFDDj0p21J8yy6qHeOEZUrPn8TOVNpU/s800/y_iinline.gif" alt="y_i"/> denotes an observed value of the time series and <img class="latex-inline" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGfCit2O3-WmYyZuKhFjOKFmiPEuV26NI5OVnJ3uoXNxiltVUNspH8D-eiKHD6-7xdypMuOtLfPIVzwEpj_BxBuPQQvk1GhzV-pFrcAQBepS20URX92to1RAHuYtcirPkpXIB2pGtcMMA/s800/S_iinline.gif" alt="S_i"/> a SEWMA value. In words, this recursive definition expresses that the next SEWMA value is a weighted average of the curent observed and SEWMA values.<br /><br />If I pose the question "What is the predicted value for the next time series observation?" we just apply the formula.<br /><br /><br /><span style="font-weight:bold;">A typical imperative implementation</span><br /><pre class="brush: plain;">sewma <- function (alp, y) {<br /> S <- y[1]<br /> for (t in 2:length(y)) { S <- alp * y[t] + (1-alp) * S }<br /> S<br />}</pre>This is <a href="http://www.r-project.org/">R</a> code, but it should look familiar enough to anyone who has written Java, C#, etc.<br /><br /><br /><span style="font-weight:bold;">Haskell implementation</span><br />In <a href="http://haskell.org/">Haskell</a>, a <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">fold</a> is a way of recursively iterating a data structure, accumulating a return value. The left fold has type <br /><pre class="brush: plain;">foldl :: (a -> b -> a) -> a -> [b] -> a<br />foldl f s y = ...</pre>Denote one of the values from the conceptual sequence of accumulator values as <img class="latex-inline" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGfCit2O3-WmYyZuKhFjOKFmiPEuV26NI5OVnJ3uoXNxiltVUNspH8D-eiKHD6-7xdypMuOtLfPIVzwEpj_BxBuPQQvk1GhzV-pFrcAQBepS20URX92to1RAHuYtcirPkpXIB2pGtcMMA/s800/S_iinline.gif" alt="S_i"/>. The function <code>f</code> maps from the current accumulator and list values to the next accumulator value<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIA6dY2D3s1DlsJtMmkuJQE6bRggGIz3B8etdEiMlvY_TKDwb8CQdvLCqzriIV7gcXiLIVD9JGAaGe_Onjl5ZHz5_5iHs_upk8zSfksQnkeQzHzE_aAJ_yyFdwlhrpGtRzHpbnRic9v3g/s800/foldlf.gif" alt="S_{t+1} = f\left(S_t, y_t \right)"/><br /><br />which is the form of the SEWMA equation above. The <a href="http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Data-List.html#v%3Afoldl1"><code>foldl1</code></a> function is a specialisation of <code>foldl</code> that uses the first value of the list as the initial accumulator value, yielding the implementation<pre class="brush: plain;">sewma alp = foldl1 (\s y -> alp * y + (1-alp) * s)</pre><br /><br /><span style="font-weight:bold;">Revisiting R</span><br />R has the <code>Reduce</code> function for performing folds. <pre class="brush: plain;">sewma <- function (alp, ys) {<br /> Reduce(function (S, y) { S <- alp * y + (1-alp) * S }, ys[2:length(ys)], ys[1])<br />}</pre><br /><br /><span style="font-weight:bold;">Summary</span><br />If accumulating a value over a data structure can be represented with a step function of the form<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIA6dY2D3s1DlsJtMmkuJQE6bRggGIz3B8etdEiMlvY_TKDwb8CQdvLCqzriIV7gcXiLIVD9JGAaGe_Onjl5ZHz5_5iHs_upk8zSfksQnkeQzHzE_aAJ_yyFdwlhrpGtRzHpbnRic9v3g/s800/foldlf.gif" alt="S_{t+1} = f\left(S_t, y_t \right)"/><br /><br />then a left fold captures the recursive implementation.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-46262812415640423162010年09月06日T19:57:00.004+10:002010年09月06日T20:31:40.530+10:00Haskell mode in MacVimI set up <a href="http://projects.haskell.org/haskellmode-vim/">Haskell mode</a> (haskellmode-20100622.vba) in <a href="http://code.google.com/p/macvim/">MacVim</a> 7.3 (53). As a Vim newbie I found this <a href="http://splonderzoek.blogspot.com/2009/04/haskell-mode-for-vim-on-mac.html">page</a> useful, even though it says pretty much the same thing as the Haskell mode project page.<br /><br />I followed the instructions and created <code>$HOME/.vimrc</code> with these contents.<br /><pre class="brush: plain;">" use ghc functionality for haskell files<br />au Bufenter *.hs compiler ghc<br /><br />" switch on syntax highlighting<br />set syntax on<br /><br />" enable filetype detection, plus loading of filetype plugins<br />set filetype plugin on<br /><br />" Configure browser for haskell_doc.vim<br />let g:haddock_browser = "open"<br />let g:haddock_browser_callformat = "%s %s"</pre>Unfortunately when I edited a Haskell file none of the Haddock integration was working. I assume the <code>haskell_doc.vim</code> filetype plugin wasn't being loaded because the <code>:DocSettings</code> command failed with <code>E492: Not an editor command</code>.<br /><br />After some hours I changed the line <code>set filetype plugin on</code> to <code>:filetype plugin on</code> and Haddock integration now works (don't know why). I am using the <a href="http://hackage.haskell.org/platform/">Haskell Platform</a> which includes the documentation.<br /><br />After reading <a href="http://b4winckler.wordpress.com/2009/07/10/a-minimal-vim-configuration/">A minimal Vim configuration</a> I have switched from <code>$HOME/.vimrc</code> to <code>$HOME/.gvimrc</code> with these contents.<br /><pre class="brush: plain;">" line numbers<br />set number<br /><br />" show the cursor line and column number<br />set ruler<br /><br />" turn off blinking cursor in normal mode<br />set gcr=n:blinkon0<br /><br />" hide the toolbar<br />set go-=T<br /><br />" switch on syntax highlighting<br />set syntax<br /><br />" highlight matches in a search (hls)<br />" show the current matching pattern as you search (is),<br />" ignore case (ic) unless you are searching for both upper and lowercase letters (scs)<br />set hls is ic scs<br /><br />" use ghc functionality for haskell files<br />au Bufenter *.hs compiler ghc<br /><br />" enable filetype detection, plus loading of filetype plugins<br />:filetype plugin indent on<br /><br />" Configure browser for haskell_doc.vim<br />let g:haddock_browser = "open"<br />let g:haddock_browser_callformat = "%s %s"</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-76367476558650260722010年07月28日T12:44:00.004+10:002010年07月28日T12:47:40.618+10:00GMail down<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1r2VFrTmQNk1wpuYHMEH-b9ZWnkiRfBIsZZrLzsPMJLu9U6Qm7pY0tS4-cX_S0VoeGvVMvNQSxirMLXSVMvyjIugL2URdho8n5fGLyMwuuOoJ91K_Eqa891lquqn6Pz69brh6kpMaCFs/s1600/gmaildown.jpg"><img style="cursor:pointer; cursor:hand;width: 400px; height: 294px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1r2VFrTmQNk1wpuYHMEH-b9ZWnkiRfBIsZZrLzsPMJLu9U6Qm7pY0tS4-cX_S0VoeGvVMvNQSxirMLXSVMvyjIugL2URdho8n5fGLyMwuuOoJ91K_Eqa891lquqn6Pz69brh6kpMaCFs/s400/gmaildown.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5498783271267602034" /></a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-91547118352090951252010年07月12日T21:26:00.004+10:002010年07月12日T21:37:55.455+10:00Charles Leadbeater: Education innovation in the slums (TED talk)<ul><li>education that works by pull not push</li><br /><li>learning has to be productive to make sense</li><br /><li>learning that starts from questions not from knowledge in curriculum</li><br /><li>Chinese restaurant model instead of McDonalds model</li><br /><li>technology that makes learning fun and accessible</li></ul><br />In these models, it seems the "teacher" plays more of a mentor type role of guiding and encouraging.<br /><br /><object width="446" height="326"><param name="movie" value="http://video.ted.com/assets/player/swf/EmbedPlayer.swf"></param><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"></param><param name="bgColor" value="#ffffff"></param> <param name="flashvars" value="vu=http://video.ted.com/talks/dynamic/CharlesLeadbeater_2010S-medium.flv&su=http://images.ted.com/images/ted/tedindex/embed-posters/TedTalks-1609.embed_thumbnail.jpg&vw=432&vh=240&ap=0&ti=892&introDuration=15330&adDuration=4000&postAdDuration=830&adKeys=talk=charles_leadbeater_on_education;year=2010;theme=new_on_ted_com;theme=how_we_learn;theme=unconventional_explanations;event=TEDSalon+London+2010;&preAdTag=tconf.ted/embed;tile=1;sz=512x288;" /><embed src="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" pluginspace="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" bgColor="#ffffff" width="446" height="326" allowFullScreen="true" allowScriptAccess="always" flashvars="vu=http://video.ted.com/talks/dynamic/CharlesLeadbeater_2010S-medium.flv&su=http://images.ted.com/images/ted/tedindex/embed-posters/TedTalks-1609.embed_thumbnail.jpg&vw=432&vh=240&ap=0&ti=892&introDuration=15330&adDuration=4000&postAdDuration=830&adKeys=talk=charles_leadbeater_on_education;year=2010;theme=new_on_ted_com;theme=how_we_learn;theme=unconventional_explanations;event=TEDSalon+London+2010;"></embed></object>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-87043726529779759312010年07月07日T16:40:00.001+10:002010年07月09日T09:33:09.484+10:00Managing PDF books and papersI have a small collection of mathematical and computer science books and papers as PDF files. Some are stashed in <a href="https://docs.google.com/">Google Docs</a>, others in <a href="http://readitlaterlist.com/">Read it Later</a> and others as links in email, etc. It would be nice if:<br /><ul><li>all documents were organised together</li><br /><li>I could access the documents from all my devices - work and home macs and iPad</li><br /><li>adding / removing documents automatically synchronised across all devices</li><br /><li>there is a record of the url each document came from</li><br /><li>document contents are searchable</li></ul><br />A cloud solution with device specific apps would be a good start. I would be happy to pay an annual price similar to <a href="http://flickr.com/">flickr</a> and <a href="https://rememberthemilk.com/">Remember the Milk</a> for a good product. From memory these are about USD25ドル / year.<br /><br />All the solutions I have come across are intended for academic bibliographic management. Most of my documents were collected adhoc from the web, without access to restricted channels such as the <a href="http://portal.acm.org/dl.cfm">ACM Digital Library</a>. The tools are geared towards searching the popular open and paid publication repositories and extracting bibliographic details automatically. I can see how this would be very useful if you have access, but I found it problematic in matching my documents when I don't have access. Given my requirements this became more hassle then it was worth.<br /><br />Some solutions integrate social networking. Being able to share your reading and observe what others are reading might be quite useful. Warrants future investigation.<br /><br />I don't have any need to annotate, highlight or add notes to the PDF files at present.<br /><br /><a href="http://mekentosj.com/papers/">Papers</a><br />A Mac application (USD42ドル) featuring document synchronisation with the corresponding iPhone and iPad apps (USD17ドル.99). Storing the database and documents on <a href="https://www.dropbox.com/">Dropbox</a> should also enable sharing between Macs. Metadata and content are searchable and the full screen reading mode is great. You can add notes to documents, but not annotate or highlight portions. At work I am behind a strict corporate firewall and proxy. Papers gave a spurious error about internet connectivity and disabled all online actions. Following this forum <a href="http://mekentosj.com/papers/forum15/viewtopic.php?id=3200">post</a> fixed things up.<br /><br />I had high hopes for Papers. The iPad synchronisation is very compelling, but otherwise it currently doesn't do enough for me to warrant paying money for (and putting my data in) Mac only software. If I end up regularly using the supported repositories then I will probably reconsider.<br /><br /><a href="http://www.mendeley.com/">Mendeley</a><br />A web application with a companion Mac/Windows/Linux desktop app. There is no iPad app, although it is apparently in the works. The desktop UI looks like it is Java and is a bit clunky on the Mac.<br /><br />The desktop app is orientated around managing your documents and associated files. You can add your files, set their metadata and sync with your website account. Synchronisation is initiated manually via a UI button. There is a full screen viewer, although I couldn't figure out the zoom and navigation keys. Alternatively you can open documents with the default external application. Document annotations, highlighting and notes are all supported, as well as full text searching. Unfortunately the network proxy settings aren't automatically detected from System Preferences and I need to manually edit them when taking the MacBook Pro between work and home.<br /><br />On the website you can manage your references and notes and view your files, but I couldn't figure out how to upload files or see annotations and highlighting. Otherwise, the web site is all about social networking. You get 500MB of personal storage space and 500MB of shared space. The first upgrade is USD4ドル.99/month for 3.5GB + 3.5GB.<br /><br />To make it attractive for me, Mendeley needs to tidy up the desktop app, automatically sync in the background, make the full screen view useful, release a synchronised iPad app and lower the price.<br /><br /><a href="http://bibdesk.sourceforge.net/">BibDesk</a> + <a href="https://www.dropbox.com/">Dropbox</a> + <a href="http://skim-app.sourceforge.net/">Skim</a> + <a href="http://www.goodiware.com/goodreader.html">GoodReader</a><br />BibDesk is a Mac <a href="http://www.bibtex.org/">BibTex</a> editor and reference manager. I can record as much metadata as is convenient, associate url's and PDF files, organise and search. By storing the BibDesk database file and PDF files on Dropbox, both content and metadata is automatically synchronised between all Macs. Dropbox provides 2GB of free storage, which is a great to get started. Skim is a PDF reader with a decent full screen mode on the Mac. GoodReader (USD1ドル.19) is a PDF viewer with Dropbox integration on the iPad. Although it is much quicker to transfer documents to GoodReader via iTunes.<br /><br />The main downside with this setup is the lack of BibDesk support on the iPad and that all documents aren't automatically synchronised locally to the iPad. It is sufficient for me now though, as I am currently only adding new documents periodically.<br /><br /><a href="http://www.citeulike.org/">CiteULike</a><br />Web site sponsored by Springer. I haven't investigated it properly, but it looks like you can add references from the major publication repositories or add your own, upload the associated documents and setup social connections. There are no Mac or iPad apps, so you need to manage your local files and how to view them yourself.Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-2069754202671317458.post-78435642727347666092010年07月02日T08:43:00.003+10:002010年07月03日T15:09:23.012+10:00QOTD<blockquote>Do not have the mind set that the day you release version 1.0 is the finish line, it’s the starting line, so hurry up and get there.<br /><br />-- Sam Howley</blockquote><br />From: <a href="http://successfulsoftware.net/2010/05/27/learning-lessons-from-13-failed-software-products/">Lessons learned from 13 failed software products</a> via <a href="http://twitter.com/ericries">@ericries</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-76348175067294491632010年06月29日T12:46:00.002+10:002010年06月29日T12:50:40.451+10:00QOTD<blockquote>It's not that people cannot think mathematically. It's that they have enormous trouble doing it in a de-contextualized, abstract setting.<br /><br />-- Keith Devlin</blockquote><br />From <a href="http://www.maa.org/devlin/devlin_06_10.html">In Math You Have to Remember, In Other Subjects You Can Think About It</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-18602727565715519452010年06月22日T09:56:00.008+10:002010年06月29日T12:51:08.125+10:00Masters to Graduate DiplomaIn 2008 I commenced a coursework Masters in mathematics at the University of Queensland. I have downgraded this to a Graduate Diploma and should officially graduate in a few weeks.<br /><br />My original goal for commencing postgraduate study was to improve my knowledge in programming languages and make the current research more accessible. Unfortunately the local universities teach very little (relevant) theoretical computing science, so I enrolled in mathematics with a focus on discrete mathematics, logic and abstract algebra. After the first year I discovered that there is no real future in programming language research here in Brisbane. I had achieved my goal in the context of the courses available and so switched my study to statistics as data analytics is both interesting and hopefully more viable locally.<br /><br />To complete the Masters I need to do the equivalent of four courses in research. As I am enrolled in a coursework masters, I pay 2-3 times the standard undergraduate fees. The last course cost 2010ドル. Therefore there is approximately 8000ドル in fees remaining. <br /><br />I would enjoy the remaining Masters research component if could find the right supervisor and topic. However employment as a researcher now generally requires a PhD, not a Masters and while a PhD is longer, it also has no fees. So if the circumstances were right to do the Masters research it makes more sense to consider a PhD anyway.<br /><br />The value proposition for completing the Masters is too low. I have fulfilled the requirements for a Graduate Diploma and so will finish with that.Unknownnoreply@blogger.com7tag:blogger.com,1999:blog-2069754202671317458.post-22858013554559757872010年05月25日T10:08:00.003+10:002010年05月25日T10:38:49.947+10:00Education is not linear<object width="446" height="326"><param name="movie" value="http://video.ted.com/assets/player/swf/EmbedPlayer.swf"></param><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"></param><param name="bgColor" value="#ffffff"></param> <param name="flashvars" value="vu=http://video.ted.com/talks/dynamic/SirKenRobinson_2010-medium.flv&su=http://images.ted.com/images/ted/tedindex/embed-posters/SirKenRobinson-2010.embed_thumbnail.jpg&vw=432&vh=240&ap=0&ti=865&introDuration=15330&adDuration=4000&postAdDuration=830&adKeys=talk=sir_ken_robinson_bring_on_the_revolution;year=2010;theme=new_on_ted_com;theme=master_storytellers;theme=a_taste_of_ted2010;theme=how_the_mind_works;theme=the_creative_spark;theme=the_rise_of_collaboration;theme=whipsmart_comedy;theme=how_we_learn;event=TED2010;&preAdTag=tconf.ted/embed;tile=1;sz=512x288;" /><embed src="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" pluginspace="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" bgColor="#ffffff" width="446" height="326" allowFullScreen="true" allowScriptAccess="always" flashvars="vu=http://video.ted.com/talks/dynamic/SirKenRobinson_2010-medium.flv&su=http://images.ted.com/images/ted/tedindex/embed-posters/SirKenRobinson-2010.embed_thumbnail.jpg&vw=432&vh=240&ap=0&ti=865&introDuration=15330&adDuration=4000&postAdDuration=830&adKeys=talk=sir_ken_robinson_bring_on_the_revolution;year=2010;theme=new_on_ted_com;theme=master_storytellers;theme=a_taste_of_ted2010;theme=how_the_mind_works;theme=the_creative_spark;theme=the_rise_of_collaboration;theme=whipsmart_comedy;theme=how_we_learn;event=TED2010;"></embed></object><br /><br /><blockquote>And we have sold ourselves into a fast food model of education and it's impoverishing our spirits and our energies as much as fast food is depleting our physical bodies.<br /><br />-- Ken Robinson</blockquote>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-63990580737853599152010年05月11日T08:00:00.000+10:002010年05月11日T08:31:36.416+10:00Brief summary of iPhone Flickr appsI use <a href="http://www.flickr.com/">Flickr</a> to store my photos. Now that I have an iPhone, I would like to use it as a mobile photo album as well as uploading photos taken from the camera. I don't want the added complexity of using iPhoto as a middleman, so I did a rough survey of iPhone Flickr apps.<br /><br /><a href="http://itunes.apple.com/au/app/flickr/id328407587">Flickr</a> 1.1.3 (free).<ul><li>Loads photos fast. Caching works well if you have already viewed a photo.</li><br /><li>View photos full screen and swipe to navigate.</li><br /><li>No zoom.</li><br /><li>If you take photos with the inbuilt Camera app and upload them sometime later, it doesn't set the map location and time taken to the original values.</li><br /><li>Uploaded photo file size seems larger than with Mobile Fotos or syncing with iPhoto.</li></ul><br /><a href="http://connectedflow.com/darkslide/">Darkslide</a> 1.6.2 (free add-supported version)<ul><li>Slow load times (even for previously viewed photos).</li><br /><li>No swipe to nagivate photos.</li><br /><li>No zoom.</li></ul><br /><a href="http://www.greenvolcanosoftware.com/flickit.html">Flickit</a> 2.0 (free)<br /><ul><li>Only does uploading. The Pro app (5ドル.99) is a full client.</li><br /><li>If you take photos with the inbuilt camera app and upload them sometime later, it doesn't set the map location and time taken to original values. Found an <a href="http://www.jasonhansen.net/2009/02/12/flickit-for-iphone/">explanation</a> from the developer.</li><br /><li>Compresses photos significantly. I could only see small differences compared with the same photo uploaded via alternative means. Developer was helpful when I asked about this.</li></ul><br /><a href="http://mobilefotosapp.com/">Mobile Fotos</a> (5ドル.99)<br /><ul><li>Upload correctly sets the map location and time taken to the original values for photos taken with the inbuilt Camera app.</li><br /><li>View photos full screen, swipe to navigate and pinch to zoom.</li><br /><li>Slideshow.</li><br /><li>Uploaded photos have washed out colours.</li><br /><li>Can't select from your tags when uploading, need to type in each time.</li><br /><li>Had one case where photos were shown as a blank screen. Cleared cache and problem was resolved.</li><br /><li>Developer was responsive when I asked questions.</li></ul><br /><a href="http://orangepetal.com/reflections/">Reflections</a> (5ドル.99) and <a href="http://www.midnightmobility.com/">Photo Wallet: Flickr</a> (3ドル.99) both look interesting in their own right, but neither offer zoom. The developer of Photo Wallet answered my question via twitter quickly to.<br /><br />In summary, none of the Apps I tried are ideal for uploading to Flickr. This leaves me importing into iPhoto and uploading via the standard web uploader.* Mobile Fotos has the best viewing experience and I would also use it for uploading if the colours and tagging were fixed.<br /><br />* The iPhone saves GPS information into the EXIF data. I had to set the "Import EXIF location data" privacy setting for the Flickr map location to be set. The privacy implications of this need further investigation.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-75327354225187573572010年04月13日T21:06:00.001+10:002010年04月13日T21:08:29.153+10:00Math is not linear<div class="prezi-player"><style type="text/css" media="screen">.prezi-player { width: 550px; } .prezi-player-links { text-align: center; }</style><object id="prezi_aww2hjfyil0u" name="prezi_aww2hjfyil0u" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="550" height="400"><param name="movie" value="http://prezi.com/bin/preziloader.swf"/><param name="allowfullscreen" value="true"/><param name="allowscriptaccess" value="always"/><param name="bgcolor" value="#ffffff"/><param name="flashvars" value="prezi_id=aww2hjfyil0u&amp;lock_to_path=1&amp;color=ffffff&amp;autoplay=no"/><embed id="preziEmbed_aww2hjfyil0u" name="preziEmbed_aww2hjfyil0u" src="http://prezi.com/bin/preziloader.swf" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="550" height="400" bgcolor="#ffffff" flashvars="prezi_id=aww2hjfyil0u&amp;lock_to_path=1&amp;color=ffffff&amp;autoplay=no"></embed></object><div class="prezi-player-links"><p><a title="description" href="http://prezi.com/aww2hjfyil0u/math-is-not-linear/">Math is not linear</a> on <a href="http://prezi.com">Prezi</a></p></div></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-42050398195332794122010年03月21日T10:52:00.001+10:002010年03月23日T12:31:56.874+10:00Embedding LaTeX in Blogger take 2After further consideration on <a href="http://bradclow.blogspot.com/2010/03/embeding-latex-in-blogger.html">Embedding LaTeX in Blogger</a> I have the following concerns in using <a href="http://blog.dreasgrech.com/2009/12/jslatex-jquery-plugin-to-directly-embed.html">jsLaTeX</a>.<br /><ul><li>LaTeX images not rendered in RSS readers</li><br /><li>Stability of all the components over (a long) time</li></ul><br /><a href="http://www.math.union.edu/~dpvc/jsMath/">jsMath</a> improves on point 2, but looks way too hard to host on Blogger. So I am falling back to using images generated by the <a href="http://www.codecogs.com/components/equationeditor/equationeditor.php">CodeCogs online equation editor</a> hosted on Picasa, which is where Blogger uploads images. I put the LaTeX source in the <code>img alt</code> attribute.<br /><br /><span style="font-weight:bold;">Blogger resizing images</span><br />After adding a few equations through the standard Blogger mechanism, I noticed that they weren't as clear when previewing. The following two equations are the same image hosted on Picasa, but embedded with different src urls.<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfIghW5xx5d_kaApPxg_FunC49I1gpK8dyYtPuHNyKwT4eEZ40yFN9vRMDGS8dldsJrb8T7d7fx6sgM-KzUIPjoXBhp9tekXdX9WxuTl_oSxU7FDSRHshtLy4j72jK9xe5LZDwrV765q0/s400/obsvariance2deriv.gif"/><br /><br />This is using the Blogger generated url in the image tag and has size 400 x 285 pixels.<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfIghW5xx5d_kaApPxg_FunC49I1gpK8dyYtPuHNyKwT4eEZ40yFN9vRMDGS8dldsJrb8T7d7fx6sgM-KzUIPjoXBhp9tekXdX9WxuTl_oSxU7FDSRHshtLy4j72jK9xe5LZDwrV765q0/s800/obsvariance2deriv.gif"/><br /><br />This is using the Picasa generated url and has the original size of 415 x 296 pixels.<br /><br />Notice how the first image is both smaller and blurry. It seems that Blogger is automatically resizing it. Unfortunately this means a little more work for each equation as it requires generating the link in Picasa and replacing the Blogger generated image tag.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-91289178342481738962010年03月21日T09:48:00.006+10:002010年03月23日T12:35:16.964+10:00Computing varianceGiven a list of <code>n</code> numbers <img class="latex-inline" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRPyA30jV03ijG4Z62L4E5ApHRS3MeZQfQRHRp7zRguY1UIc3juk6E9AF5hQBrB8dpuYjnqrnrA7cwiB8ji8YHs36rlJmY4RHcVnOpe6P-rbVir7XckjEyQnDKZX3fI5TeVnc2MJD-g1Y/s800/x1toxninline.gif" alt="x_1,x_2,...,x_n"/>, the <a href="http://en.wikipedia.org/wiki/Variance">variance</a> is defined as<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijpEMmBNOdOGDbHEVZ7pFY_JWoHi9qOR35coI66luIWegBMHBBLDpuLyul9r2Ig_eFSGnBwIHVXT6hSmaxMajAbhpsIii1MJaGsYQY4jZ_ZLY49mbYfgm2ZRpniLMDq1WTGiT9y5uFpB4/s800/obsvariancenum1.gif" alt="\frac{1}{n}\sum_{i=1}^n{\left(x_i - \bar{x}\right)^2}\quad\quad\quad\text{(1)}"/><br /><br />where <img class="latex-inline" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLQjIozs5rlJbH6FCkjKmfFLV79xHVyQoX_4VKM8txkoC4e210FYtmzTXPzJovN8K9GbtlQ9-dQefJjkt7UaqRA-owy2Vp2zKvH7s8vByFQwcMHztdfO07kaFe79c63y-8lJKuGTLqIjw/s800/xbar.gif" alt="\bar{x}"/> is the <a href="http://en.wikipedia.org/wiki/Arithmetic_mean">arithmetic mean</a>.<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibB7gKWxEU8wsWj77FVdJTujp0576MoYa2-xzRtt91FWQZHG3F9At6hVx_00eMR1PpcySaSkfx_oVb31CC7mJ3qJh7k7btwnLO3ZltLlpx_AGm94FMVqKgwwU-TGYK1NUpYgHnaqlwdWQ/s800/xbardef.gif" alt="\bar{x} = \frac{1}{n}\sum_{i=1}^n{x_i}"/><br /><br />Expression 1 stated in words is the average squared difference of each data point from the mean. Implemented as an algorithm, this requires two passes over the data set. The first to calculate the mean and the second to sum the squared differences.<br /><br />Let's derive the more commonly used expression for variance.<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfIghW5xx5d_kaApPxg_FunC49I1gpK8dyYtPuHNyKwT4eEZ40yFN9vRMDGS8dldsJrb8T7d7fx6sgM-KzUIPjoXBhp9tekXdX9WxuTl_oSxU7FDSRHshtLy4j72jK9xe5LZDwrV765q0/s800/obsvariance2deriv.gif" alt="\begin{align*}<br />\frac{1}{n}\sum_{i=1}^n{\left(x_i - \bar{x}\right)^2} & = \frac{1}{n}\sum_{i=1}^n{\left({x_i}^2 - 2x_i\bar{x} + \bar{x}^2\right)} \\<br />& = \frac{1}{n}\left(\sum_{i=1}^n{x_i}^2 - 2\bar{x}\sum_{i=1}^n{x_i} + n\bar{x}^2\right) \\<br />& = \frac{1}{n}\sum_{i=1}^n{x_i}^2 - 2\bar{x}^2 + \bar{x}^2 \\<br />& = \frac{1}{n}\sum_{i=1}^n{x_i}^2 - \bar{x}^2 \\<br />& = \frac{1}{n}\sum_{i=1}^n{x_i}^2 - \left(\frac{1}{n}\sum_{i=1}^n{x_i}\right)^2 && \text{(2)}<br />\end{align*}"/><br /><br />This only requires a single pass over the data set, computing the incremental sum of the values and the incremental sum of their squares. However, if the terms in the subtraction are large and close enough, <a href="http://en.wikipedia.org/wiki/Catastrophic_cancellation">catastrophic cancellation</a> can occur. Essentially the precision of the floating point representation is exceeded, yielding unacceptable results. See <a href="http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance">Algorithms for calculating variance</a> and <a href="http://www.johndcook.com/blog/2008/09/28/theoretical-explanation-for-numerical-results/">Theoretical explanation for numerical results</a> for examples (they are calculating the sample variance which is slightly different). More detailed information on catastrophic cancellation can be found in <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.22.6768">What Every Computer Scientist Should Know About Floating Point Arithmetic (1991)</a>.<br /><br />A more numerically stable (but computationally expensive) single pass <a href="http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#On-line_algorithm">algorithm</a> was published by Knuth in The Art of Computer Programming, volume 2. Define <img class="latex-inline" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWxlF5bUM4NdLHQyJL8pMC8XEatEjZPlTSQtHHfsFrnnqoZLDXbRw71_gp8s9KY2wyJsMnNnax4_hB4-TTvLv5CBOdBvUpDR9X7ZT9fWDytyHSkn_rkZ2mrrp4tMjnBpg1G_QqJxs8XUQ/s800/xbarninline.gif" alt="\bar{x}_n"/> and <img class="latex-inline" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnBEJ0CVUe44pNI3jZmMYlTq-RYJCOTk92FU9rwb1QDHfzk0nIBFq1QMakN6WVi0BFbAVifwEThIJ_YtnzQhQoUMGOZU9HJ_bd2D8ZPJTnutVaqN2SRJNYRjF3FyA0Z3F7fh9ZujchKk8/s800/sninline.gif" alt="s_n"/> as the mean and sum of squared differences of the the first n values respectively.<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibKjI20k4dE3Bmgrc94QE2Oy3dEYkZUgnSmPqlHHJjhkO8uLjBGT_k9ZqK-wxHCXY-5FHGRTZNgGaOuB_aCGIUHyVrAFzI-UuJ-z8ZnICfo72_UezfP_3Cj1Vrg1XrtoDEdzw_EiJxX5M/s800/runningsumofsquares.gif" alt="\begin{align*}<br />s_0 & = 0\\<br />\\<br />s_{n+1} & = \sum_{i=1}^{n+1}\left(x_i-\bar{x}_{n+1}\right)^2\\<br />& = s_n + \left(x_{n+1}-\bar{x}_n\right)\left(x_{n+1}-\bar{x}_{n+1}\right)\quad\quad\quad(3)<br />\end{align*}"/><br /><br />For <code>m > 0</code> values, the variance is then <img class="latex-inline" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZPLa-VKS517dNZP4UduEnHPhF2oyay4CnuLTUh0oqBR7-EH0Bpp1HW13nnV_rVGBV6IjIzehu_v9zbqR-xlgoK6zPS2ukwMF2tJRhEZhlydM28_552NWi5SBEQPqvv4kKZCxNAN5p3Es/s800/smonm.gif" alt="\frac{s_m}{m}"/>.<br /><br /><span style="font-weight:bold;">Derivation of Equation 3</span><br />This is really just a more verbose version of <a href="http://planetmath.org/encyclopedia/OnePassAlgorithmToComputeSampleVariance.html">one-pass algorithm to compute sample variance</a>. First up is the running mean.<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJ2UN_-ZrOChfGwfMTb1s2fYoff-B3hgptVrnq7p-P0IrkceGRPQD6l6IiOI3GSdr8rOIlaL5-7TBw_JyoLruRuwoZibB9_uUmsIbD48ALqWjX7X8wFqqTubnfS3DkCFkADWPbA8WnMaE/s800/runningmean.gif" alt="\begin{align*}<br />\bar{x}_0 & = 0\\<br />\\<br />\bar{x}_{n+1} & = \frac{n\bar{x}_n + x_{n+1}}{n+1}\\<br />& = \frac{\left(n+1\right)\bar{x}_n-\bar{x}_n+x_{n+1}}{n+1}\\<br />& = \bar{x}_n + \frac{x_{n+1}-\bar{x}_n}{n+1} && \quad &&& (4)\\<br />\end{align*}"/><br /><br />If you think of the mean visually i.e. a horizontal line through the data on a scatter plot, then it is intuitive that the sum of the distances between each point and the mean is zero.<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMNKDtPNzKHE_YjSkf36eyJ8fJRJleeQx08nengVeJTXPioaI5wEngYMmKyb81Pwbs6gQarXMnLKLPAM4TxBA6Jm80KPV5kCIntaMitWzW4rcYtg3JYiF0KyiNxwRKWEF5YV-4uTtLjQU/s800/sumdiftomeannum5.gif" alt="\sum_{i=1}^n\left(x_i-\bar{x}_n\right) & = \sum_{i=1}^nx_i-n\left(\frac{1}{n}\sum_{i=1}^nx_i\right)=0\quad\quad\quad(5)"/><br /><br />Now define <img class="latex-inline" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjN5AkTYbqBe25AgK1YnJQsL2M5Gq59gq46DSt1XHN57jCJ5C1TFCm2eUJPZ7ooIsvUINvB3raGCRSeieHq-Us0Qk9QIGebq68a99Aia_lL1TBckhruRAIYQwQlNfK2c-r0Rd396WGW3j0/s800/gammainline.gif" alt="\gamma"/> as the difference of consecutive incremental means, along with a few useful variations.<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg75kPyHhwR5_OTM5VL9_wQ982W0uhy0vtzaZQv0_j9jCh7NbfKbqMQX2LwUrqb7st0ppqTOADsa305S1UcamnTaupw1XVJoU4V4NNQuhvayNUcnFv020dPaBDdnS5iklv89TxjVYkcTdU/s800/sumofsquaresnum678.gif" alt="\begin{align*}<br />\gamma & = \bar{x}_{n+1} - \bar{x}_n && \quad &&& (6)\\<br />\\<br />\gamma & = \bar{x}_n + \frac{x_{n+1}-\bar{x}_n}{n+1} - \bar{x}_n && &&& \text{by (4)}\\<br />\gamma & = \frac{x_{n+1}-\bar{x}_n}{n+1} \\<br />\left(n+1\right)\gamma & = x_{n+1}-\bar{x}_n && &&& (7)\\<br />\\<br />x_{n+1}-\bar{x}_{n+1} & = x_{n+1}-\bar{x}_n+\bar{x}_n-\bar{x}_{n+1} \\<br />& = \left(n+1\right)\gamma-\gamma && &&& \text{by (7, 6)} \\<br />& = n\gamma && &&& (8)\\<br />\end{align*}"/><br /><br />The pieces are now all in place to derive equation 3.<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm7G58v65Nh2Wz3ccMZo-usK5CgJlhSocsICs-MFrZiZ956t-5H6vDHELgQ8YLjO9xECDC-3pbTTAuSTLwEV_Xc-eOos_Zs2WJ5ox8szcrpVFLPTNguZ08NIXHL4DDNSvgP8sBMyOj1Hw/s800/snplus1deriv.gif" alt="\begin{align*}<br />s_{n+1} & = \sum_{i=1}^{n+1}\left(x_i-\bar{x}_{n+1}\right)^2\\<br />& = \sum_{i=1}^{n}\left(x_i-\bar{x}_{n+1}\right)^2 + \left(x_{n+1}-\bar{x}_{n+1}\right)^2\\<br />& = \sum_{i=1}^{n}\left(x_i-\bar{x}_n+\bar{x}_n-\bar{x}_{n+1}\right)^2 + \left(n\gamma\right)^2 && \quad &&& \text{by (8)}\\<br />& = \sum_{i=1}^{n}\left(\left(x_i-\bar{x}_n\right)-\gamma\right)^2+n^2\gamma^2 && &&& \text{by (6)}\\<br />& = \sum_{i=1}^{n}\left(x_i-\bar{x}_n\right)^2 -2\gamma\sum_{i=1}^{n}\left(x_i-\bar{x}_n\right)+n\gamma^2+n^2\gamma^2\\<br />& = s_n-0+n\gamma^2\left(1+n\right) && &&& \text{by (5)}\\<br />& = s_n+\left(x_{n+1}-\bar{x}_n\right)n\gamma && &&& \text{by (7)}\\<br />& = s_n+\left(x_{n+1}-\bar{x}_n\right)\left(x_{n+1}-\bar{x}_{n+1}\right) && &&& \text{by (8)}<br />\end{align*}"/>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2069754202671317458.post-7661164075349124722010年03月12日T10:41:00.010+10:002010年03月23日T12:29:52.312+10:00Embeding LaTeX in BloggerThe goal is to include mathematical equations in blog posts. My plan was to create images from the output of <a href="http://www.tug.org/mactex/">MacTeX</a>. Apart from being painfully slow to crop and upload with multiple distinct equations, the LaTeX source would not be contained in the post.<br /><br /><a href="http://measuringmeasures.com/blog/2010/2/19/embedding-latex-in-html.html">Embedding LaTeX in HTML</a> led me to <a href="http://blog.dreasgrech.com/2009/12/jslatex-jquery-plugin-to-directly-embed.html">jsLaTeX</a>. Option 4 from <a href="http://quiterandom.com/tutorials/solutions-for-js-hosting/">Solutions for JavaScript Hosting in Blogger</a> solved the Blogger hosting issue. After some CSS shenanigans we have <a href="http://en.wikipedia.org/wiki/Bayes%27_theorem">Bayes rule</a> right here, right now.<br /><br /><img class="latex" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr69Lyd5CCIFLZDVHMG3VPF_UWIXyinrvi-SAyXStwdXQmHROn3MtCR5nFY0CJvYn4B5imDki0PZAq7iKFBJHBLGLRhsXA7D0ozBoukcCuZpy0T1l8sTttG3tX0yiOBT_hldanPjnV0Pw/s800/bayes.png" alt="\mathbb{P}(B_j|A) = \frac{\mathbb{P}(A|B_j)\mathbb{P}(B_j)}{\sum_{i=1}^n\mathbb{P}(A|B_i)\mathbb{P}(B_i)}"/><br /><br />It is easier to write simple equations in the <a href="http://www.codecogs.com/components/equationeditor/equationeditor.php">CodeCogs online equation editor</a> first as Blogger preview doesn't seem to execute the JavaScript to render them.<br /><br /><span style="font-weight:bold;">Edit 23/03/2010:</span> No longer using jsLaTeX, see <a href="http://bradclow.blogspot.com/2010/03/embedding-latex-in-blogger-take-2.html">Embedding LaTeX in Blogger take 2</a>.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-2069754202671317458.post-49324869810122357942010年02月19日T14:47:00.011+10:002010年02月20日T16:59:08.621+10:00F# examples talk at BFGEarlier this week I gave a short talk at the Brisbane Functional Group on <a href="http://www.fsharp.net/">F#</a>. The idea was to give an introductory feel for the language by way of some simple examples. The talk was intended to be short so I assumed knowledge of previously discussed idioms such as tuples and curried type signatures.<br /><br />I took the examples (with permission :-) from the environmental sensing project I work on at <a href="http://www.mquter.qut.edu.au/">MQUTeR</a>. This post is intended as a reference for those who attended rather than a self-contained introduction to F#.<br /><ol><li>The <code>uncurry</code> function was first up.<br /><pre class="brush: plain;">let uncurry f (x,y) = f x y</pre>We talked about the syntax of function definition, tuples and type inference in Visual Studio. We inserted the function into F# Interactive (the REPL available in Visual Studio) by highlighting it and pressing <code>ALT-Enter</code>. The F# Interactive transcript went something like:<br /><pre class="brush: plain;">val uncurry : ('a -> 'b -> 'c) -> 'a * 'b -> 'c<br /><br />> 1 + 2;;<br />val it : int = 3<br /><br />> uncurry (+) (1,2);;<br />val it : int = 3<br /><br />> (+) 1 2;;<br />val it : int = 3</pre>This lead to a discussion on operators and infix/prefix notation. The post <a href="http://bradclow.blogspot.com/2009/07/f-option-orelse-getorelse-functions.html">F# Option orElse getOrElse functions</a> should cover that.</li><br /><li>Next was the <code>|></code> operator, which has type signature <code>'a -> ('a -> 'b) -> 'b</code>.<br /><pre class="brush: plain;">// Haskell catMaybes<br />let catOptions xs = Seq.filter Option.isSome xs |> Seq.map Option.get<br /><br />let euclidianDist (x1, y1) (x2, y2) = (x1 - x2) ** 2.0 + (y1 - y2) ** 2.0 |> sqrt<br /><br />let spt' t a = <br /> let m = Math.Matrix.ofArray2D a<br /> allPeaks t m |> removeSmall |> dilate t m |> Math.Matrix.toArray2D<br /><br />// type signatures<br />// allPeaks : float -> matrix -> matrix<br />// removeSmall : matrix -> matrix<br />// dilate : float -> matrix -> matrix -> matrix<br />// spt' : float -> float [,] -> float [,]</pre>We briefly compared <code>|></code> with the Haskell <code>$</code> function, which has the type signature <code>(a -> b) -> a -> b</code>.</li><br /><li>A quick look at type annotations, pattern matching and Haskell like guards. The example is an implementation of the MATLAB smooth function, which calculates a moving average. We didn't dwell on the entire function, just the relevant parts.<br /><pre class="brush: plain;">(* <br />yy = smooth(y,span) sets the span of the moving average to span. span must be odd.<br /><br />If span = 5 then the first few elements of yy are given by:<br />yy(1) = y(1)<br />yy(2) = (y(1) + y(2) + y(3))/3<br />yy(3) = (y(1) + y(2) + y(3) + y(4) + y(5))/5<br />yy(4) = (y(2) + y(3) + y(4) + y(5) + y(6))/5<br />...<br />*)<br />let smooth s (a:float []) = <br /> let n = (s - 1) / 2<br /> let f i _ =<br /> let (b, l) = match i with<br /> | _ when i < n -> (0, i*2+1)<br /> | _ when i + n < a.GetLength(0) -> (i-n, s)<br /> | _ -> (i-(a.GetLength(0)-1-i), (a.GetLength(0)-1-i)*2+1)<br /> Array.sum (Array.sub a b l) / (float l) // TODO try Array.average here<br /> Array.mapi f a<br /></pre></li><br /><li><a href="http://msdn.microsoft.com/en-us/library/dd233184%28VS.100%29.aspx">Records</a> are a common kind of data type. The labels are not automatically available as functions like they are in Haskell. <br /><pre class="brush: plain;">type 'a Rectangle = {Left:'a; Top:'a; Right:'a; Bottom:'a; Width:'a; Height:'a;}<br /><br />let inline cornersToRect l r t b = {Left=l; Top=t; Right=r; Bottom=b; Width=r-l; Height=t-b;}<br />let inline lengthsToRect l t w h = {Left=l; Top=t; Right=l+w-1; Bottom=t+h-1; Width=w; Height=h;}<br />let fcornersToRect (l:float) r t b = cornersToRect l r t b // for C#<br />let left r = r.Left<br />let right r = r.Right<br />let top r = r.Top<br />let bottom r = r.Bottom<br />let bottomLeft r = (r.Left, r.Bottom)<br />let width r = r.Width<br />let height r = r.Height<br />let inline area r = r.Width * r.Height</pre><a href="http://blog.lab49.com/archives/2895">The F# overload-o-phone</a> covers our discussion on arithmetic operators. The <code>inline</code> keyword is mentioned in the comments.</li><br /><li>Finally we looked at available API documentation. I find that I generally skim API documentation by first looking at function type signatures. The <a href="http://fsharppowerpack.codeplex.com/">F# PowerPack</a> is a useful library developed by the F# team and the format of the <a href="http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/FSharp.PowerPack/Microsoft.FSharp.Math.Matrix.html">documentation</a> supports my approach.<br /><br />The F# API documentation was previously in this format. It has now been moved to <a href="http://msdn.microsoft.com/en-us/library/ee370544%28VS.100%29.aspx">MSDN</a> and the list of function type signatures is not presented for each module, rendering it almost useless.</li></ol>Along the way there were a few comments about F# being strictly evaluated and having no effect tracking system, no <a href="http://en.wikipedia.org/wiki/Type_polymorphism">higher-order parametric polymorphism</a> and no <a href="http://en.wikipedia.org/wiki/Type_class">type classes</a>.<br /><br />Thanks to everyone that participated in the discussion and I hope the talk was interesting.Unknownnoreply@blogger.com0

AltStyle によって変換されたページ (->オリジナル) /