Quantcast

Posts tagged with computer

A question I’ve googled before without success. Hopefully this answer will show up for someone who needs it. I’ll also go over the better-known uses of ? just in case.

  • To get help in R about a function like subset you type ?subset . That’s like man subset from the command line.
  • If you only know roughly what you’re looking for use double question marks: so ??nonlinear will lead to the package nlme. That’s like apropos on the command line.
  • To get a package overview, type ?xts::xts. There is no ?xts help. Packages that don’t have ?twitteR::twitteR you will need to use ??twitteR to find the help pages on ?twitteR::status-class, ?twitteR::dmGet, etc.
  • Finally, the question of the title. To get R help on punctuation such as (, {, [, `, ::, ..., +, and yes, even on ? itself, use single quotes to ‘escape’ the meaningful symbol. Examples follow:
    • ?'`'
    • ?'('
    • ?'['
    • ?'...'
    • ?'+'
    • ?'%*%'
    • ?'%x%'
    • ?'%o%'
    • ?'%%'
    • ?'%/%'
    • ?'$'
    • ?'^'
    • ?'~'
    • ?'<-'
    • ?'='
    • ?'<<-'

All of the quotation marks `, ', " use the same help file so ?'"' or ?'`' will give you the help file for ?'''.




An insufficiently ugly temporary hack is permanent.
Benjamin Black (@b6n)

(Source: blog.b3k.us)




A perlmonk asked for a “custom random number generator”. This is a non-maths person’s word for a probability distribution.

image

It was a slightly unusual case, but not hard. After I’d finished several easy steps, though, the final formula looked like it had been scrivened by a wizard:

image

Of course, I’m not a wizard; I’m not even an acolyte. The steps I took just involved (1) a certain viewpoint on probability distributions, and (2) puzzles that an 11-year-old could solve. 

This is how formulas in textbooks get to look so daunting.

 —skippable interlude— 

I guess I figured this out years ago, when I first saw the Black-Scholes-Merton formula in business school.

image

The BSM is just a continuous-time limit of “Did the stock go up or down in the last 5 minutes?” But the BSM is dressed up with such frightening language that it seems much more inscrutable than “A tree generated from two alternatives which are repeated”.

\frac{\partial V}{\partial t} + \frac{1}{2}\sigma^2 S^2 \frac{\partial^2 V}{\partial S^2} + rS\frac{\partial V}{\partial S} - rV = 0

For example in the Wikipedia article on BSM the subheads include: Greeks (), elliptic PDE’s, derivation, interpretation, criticism, extensions of the model, notation, assumptions, references. It’s 24 pagedowns long. From this pretence of sophistication follows:

I’ve seen it in biology, chemistry, and physics textbooks as well. A convoluted formula encodes the results of a simple model. Because of scientism the students commit it to memory as well as more derived results. Hopefully they come to find that it was not so complicated only a professors could understand it.

But I don’t think that’s common knowledge, so formulæ retain an impenetrable mysticism and the rituals of uncomprehending repetition continue.

 —back to the main idea— 

It needn’t be so enigmatic. I can demonstrate that by showing how the ugly beast above looks if you break it into steps. It’s simpler as several lines of code than as one formula.

Client Request

Anonymous Monk wanted a probability distribution like this:

image

with the median at x and equal probability masses between [x/y,x] and [x, x•y]

Drawrings

I’m going to take a Gaussian and map the endpoints to what the client wants.

image

The result will tend to the centre a “normal” amount of the time and yet will be squashed onto the domain the client wants.

Match up the Endpoints

I know that exp maps (−∞,0] onto (0,1]

To follow that, I need a transformation that will match (0,1) to (x/y, x). So 1 ⟼ x and 0 ⟼ x/y.

0 ⟼ x and 1 ⟼ xy

as 6 lines of Code

my $random = ...; #Gaussians, however you fry them up
if ($random <= 0) { 
$random = exp($random); #map (−∞,0) → (0,1)
$random =     ; #map (0,1) → (x, x•y)


}
else { #map (0, +∞) → (0,1)
$random = 1 − exp(−$random);  #map (0, +∞) → (0,1) ... which is the same problem as above except backwards
$random =     ; #map (0,1) → (x/y, x)

Lessons:

  1. use paper first, write code second
  2. draw a picture
  3. if necessary, break it into a simpler picture
  4. compose the answers to the parts
  5. code the pieces in separate lines

The equation at the top does decompose into the sequence of steps I just outlined. But even though it looks simple as a sequence of steps, the one-line formula is scary.




C:\WINDOWS>debug taskman.exe
-u
0D69:0000 0E            PUSH    CS
0D69:0001 1F            POP     DS
0D69:0002 BA0E00        MOV     DX,000E
0D69:0005 B409          MOV     AH,09
0D69:0007 CD21          INT     21
0D69:0009 B8014C        MOV     AX,4C01
0D69:000C CD21          INT     21
0D69:000E 54            PUSH    SP
0D69:000F 68            DB      68
0D69:0010 69            DB      69
0D69:0011 7320          JNB     0033
0D69:0013 7072          JO      0087
0D69:0015 6F            DB      6F
0D69:0016 67            DB      67
0D69:0017 7261          JB      007A
0D69:0019 6D            DB      6D
0D69:001A 206361        AND     [BP+DI+61],AH
0D69:001D 6E            DB      6E
0D69:001E 6E            DB      6E
0D69:001F 6F            DB      6F

(Source: stackoverflow.com)




Brian Beckman: Don’t Fear the Monad

  • A monoid is: ({stuff}, operations)  where the operations are associative and have a unit.
    http://25.media.tumblr.com/8796d491890057c0ab488ccf4589fc34/tumblr_mpck6hmZC11qc38e9o1_1280.jpg
  • So a monoid is a semigroup with unit. (a +0 or a ×1 or a 1_C ⟳)
  • Brian Beckman in this video expresses a monoid with two functions f:a->a and g:a->a. (same type or domain)
    image
    b∘a∘b∘a∘b∘a∘b∘a∘b∘a[⬟]
    image

    successor function and square function

    image

  • His example is addition mod 12 (integral hours on a clock).

    imageimage
  • Then the monoidal category happens when you allow f:a->b and g:b->c. (linking together different types or domains)
    image

(por jasonofthel33t)




An illustration I made for @michiexile&#8217;s A∞ for the layman.
 
The left side of the picture just explains the conventional algebraic topology setup: x₀ basepoint and composition-of-paths-which-are-functions-what-the-heck-are-we-talking-about-anymore. That&#8217;s the usual setup to explaining homotopy.
The right side of the picture represents @michiexile&#8217;s exploration of associativity. That&#8217;s (ab)c=a(bc). Simple to state in an algebraic formula, but it takes some pencil calisthenics to work out what that rule is saying!

My little innovation here was to replace parentheses () with \fbox{}es which I think are easier to read.

An illustration I made for @michiexile’s A for the layman.

 


The left side of the picture just explains the conventional algebraic topology setup: x₀ basepoint and composition-of-paths-which-are-functions-what-the-heck-are-we-talking-about-anymore. That’s the usual setup to explaining homotopy.

The right side of the picture represents @michiexile’s exploration of associativity. That’s (ab)c=a(bc). Simple to state in an algebraic formula, but it takes some pencil calisthenics to work out what that rule is saying!

image

My little innovation here was to replace parentheses () with \fbox{}es which I think are easier to read.


hi-res




Everything in computers is so much more complicated than you think.

Everything in computers is so much more complicated than you think.

(Source: Wikipedia)


hi-res




As soon as an Analytic Engine exists, it will necessarily guide the future course of science.

Whenever any result is sought by its aid, the question will arise—By what course of calculation can these results be arrived at by the machine in the shortest time?
Charles Babbage (1864)

(Source: aofa.cs.princeton.edu)




What does it mean to program in a functional style?  (por Brian Will)

  • functions can be passed—as arguments—to other functions
  • if, try, while return something
  • adhere to statelessness (no side effects, so you can see everything that a function does just looking in the one place)




(also known as C:\progra~1 in older Windowses)

Short answer: /bin or /usr/bin.

Longer answer: It depends on the distro (Ubuntu, Slack, Arch, Mint, Puppy, etc) and on what kind of program. You could think of these directories as decreasing from user land toward the bare-metal computer level. (Roughly / sort-of / not exactly.)

  • /opt/ (programs you download)
  • /bin/ (netstat, uname, wc, zcat, rm, rmdir, gzip, head, tail, last, ln, ls, kill, gawk, sleep, sort, tar, touch, vi, cat, chmod, sh, bzip2, bash, dmesg)
  • /usr/bin/ (lpr, xsane, zipgrep, xrandr, xsane, less, leafpad, ldd, xinit, dpkg, ssh, sudo, sftp, dvipdf, evince)
  • /usr/sbin/ (gtkdialog, parted, wpa_supplicant, ethtool, nscd, grub, dhcpd, httpd, cupsd, alsaconf)
  • /sbin/ ( fsck, fdisk, mount, swapon, ifup, sysctl, lspci)

You should preferably store programs you download in:

  • /opt/.

(for optional) and add /opt/ or /opt/bin/ to your $PATH with

  • echo $PATH
  • export PATH=$PATH:/opt
  • echo $PATH

(if that gives you an error you may need to give yourself access with chown or chmod. For example chown isomorphismes /opt/ or chmod -R a+rw /opt/.


If you want to find where some command or program you use is located, use which.

# which ls
/bin/ls

# which grep
/bin/grep

# which top
/usr/bin/top

# which java
/usr/bin/java

# which ghci

# which ruby
/usr/bin/ruby

# which python
/usr/bin/python

# which perl
/usr/bin/perl

# which jwm
/usr/bin/jwm

# which awesomewm

# which xinit
/usr/bin/xinit

# which latex
/usr/bin/latex

# which pdflatex
/usr/bin/pdflatex

# which dvips
/usr/bin/dvips

# which sage

# which ack-grep
/usr/bin/ack-grep

# which ack

# which gdb
/usr/bin/gdb

# which epdfview
/usr/bin/epdfiew

# which dpaste
/opt/dpaste

# which lein
/opt/lein

# which less
/usr/bin/less