2010-08-09 running embarassingly parallel simulations on a multicore machine using bash loops

2010-08-11 11:33:50
  • I need to run a single-processor experiment on some parameters, say N times

  • embarassingly parallel: pythonexperiment_all.py scans all these parameters:

    1 for i in range(N):
    2     if experiment[i] is not finished and not locked:
    3         lock(experiment[i])
    4         run(experiment[i])
    
  • to run this on 8 cores, bash is your friend (may also apply to *sh where * is either z, c, tc, ...)

    for i in {1..8}; do cd /data/work/ && python experiment_all.py  & done
    
  • however, runnning them simultaneously may cause problems if the locking mechanism is not fast enough, so I introduce a random jitter

    for i in {1..8}; do cd /data/work/ && sleep 0.$(( RANDOM%1000 )) ; python experiment_all.py  & done
    

Comments

2010-08-07 distributed computing

2010-08-07 13:42:38
  • guess you have a bunch (4000) of embarrassingly parallel tasks (one hour each) and access to about 40 CPUs through SSH. All tasks would run easily on each node, and they all share some network drive (NFS). Would be nice to run everything from just one place (script, command-line, web interface, ...)

what we can do

Comments

2010-08-05 Pinna illusion

2010-08-05 15:32:20
  • from http://www.scholarpedia.org/article/Pinna_illusion :

    Pinna illusion is the first visual illusion showing a rotating motion effect. In Figure 1  the squares, delineated by two white and two black edges each, are grouped by proximity in two concentric rings. All the squares have the same width, length, and orientation in relation to the center of their circular arrangements. The two rings differ only in the relative position of their narrow black and white edges forming the vertexes. More precisely, the two rings show reversal of the vertex orientation and, consequently, opposite inclination of the virtual or implicit diagonal orientation polarity obtained by joining the two vertexes where black and white lines meet (Pinna, 1990; Pinna & Brelstaff, 2000).
    
  • related to the aperture problem

    The Pinna illusion and the related effects represent an opportunity within the context of vision science and cognitive neuroscience  (Gazzaniga, 2004; Purves & Lotto, 2003). If the task of a sensory system is to provide a faithful representation of biologically relevant events in the external world, the previous phenomena show that visual perception  contrives, through complex neural computations, to create informative and efficient representations of the external environment. These representations are at the same time simpler and richer than the raw signals transduced by receptors. They are simpler because they simplify the enormous quantity of raw measurement information submitted to the central nervous system (see Section 2). They are richer because they contain properties of events and objects abstracted from the primitive sensory signals (see Sections 3 and 4). Therefore, the first opportunity suggested by the previous effects concerns the basic encoding of the features of the stimuli, i.e. the nature and meanings of the signals carried by single neurons, the maps and areas where they operate (see Section 2) and the pattern of motion of objects, surfaces, and edges in a visual scene due to the relative motion between an observer and the scene (optical flow, Gibson, 1979). Furthermore, they are good tests to understand the perceptual context within which a specific element is perceived, namely “what is ‘figure and what is ‘background”, “how separated elements of a visual event are combined and organized in a sensory representation” (see Section 4).
    
  • windmill illusion. link to the waghon-wheel illusion?

Comments

2010-08-03 compiling OpenCV on MacOSX 10.6

2010-08-03 12:14:29

using macports

  • it works now with macports:

    sudo port install -u opencv +python26 +tbb
    

latest SVN

  • compiling here along with MacTex...

  • from http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port

    svn co https://code.ros.org/svn/opencv/trunk/opencv
    cd opencv # the directory containing INSTALL, CMakeLists.txt etc.
    mkdir build
    cd build
    cmake -D CMAKE_OSX_ARCHITECTURES=x86_64 -D WITH_FFMPEG=ON -D BUILD_EXAMPLES=ON -D BUILD_LATEX_DOCS=ON -D PDFLATEX_COMPILER=/usr/texbin/pdflatex -D BUILD_NEW_PYTHON_SUPPORT=ON  -D PYTHON_LIBRARY=/opt/local/lib/libpython2.6.dylib -D PYTHON_INCLUDE_DIR=/opt/local/Library/Frameworks/Python.framework/Headers ..
    make -j4
    sudo make install
    
  • I had to rebuild some ports

    sudo port install ilmbase
    port provides /opt/local/lib/libIlmImf.dylib
    sudo port install openexr
    sudo port install libdc1394
    

    and recompile

  • then could run

    cd ../samples/python/
    python camera.py
    

using homebrew

  • another route is homebrew: http://gist.github.com/519418 / :

    $ brew info opencv
    opencv 2.1.1-pre
    http://opencv.willowgarage.com/wiki/
    Depends on: cmake, pkg-config, libtiff, jasper, tbb
    /usr/local/Cellar/opencv/2.1.1-pre (96 files, 37M)
    
    The OpenCV Python module will not work until you edit your PYTHONPATH like so:
      export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:$PYTHONPATH"
    
    To make this permanent, put it in your shell's profile (e.g. ~/.profile).
    
    http://github.com/mxcl/homebrew/commits/master/Library/Formula/opencv.rb
    

Comments

2010-07-08 latex within moinmoin

2011-07-06 20:59:01
  • installation d'après http://johannes.sipsolutions.net/Projects/new-moinmoin-latex

  • pour s'adapter à ma distribution pdflatex, j'ai changé

    1 # last arg must have %s in it!
    2 latex_args = ("--interaction=nonstopmode -output-format dvi", "%s.tex")
    

    dans le parser sudoopen-e~/WebSites/moin/data/plugin/parser/latex.py)

examples

This is a red square:

\usepackage{graphics,color}

%%end-prologue%%
\newsavebox{\mysquare}
\savebox{\mysquare}{\textcolor{red}{\rule{1in}{1in} } }
\usebox{\mysquare}

symboles

% Math-mode symbol & verbatim
\def\W#1#2{$#1{#2}$ &\tt\string#1\string{#2\string}}
\def\X#1{$#1$ &\tt\string#1}
\def\Y#1{$\big#1$ &\tt\string#1}
\def\Z#1{\tt\string#1}

% A non-floating table environment.
\makeatletter
\renewenvironment{table}%
   {\vskip\intextsep\parskip\z@
    \vbox\bgroup\centering\def\@captype{table}}%
   {\egroup\vskip\intextsep}
\makeatother

% All the tables are \label'ed in case this document ever gets some
% explanatory text written, however there are no \refs as yet. To save
% LaTeX-ing the file twice we go:
\renewcommand{\label}[1]{}

%%end-prologue%%
\begin{table}
\begin{tabular}{*8l}
\X\alpha        &\X\theta       &\X o           &\X\tau         \\
\X\beta         &\X\vartheta    &\X\pi          &\X\upsilon     \\
\X\gamma        &\X\gamma       &\X\varpi       &\X\phi         \\
\X\delta        &\X\kappa       &\X\rho         &\X\varphi      \\
\X\epsilon      &\X\lambda      &\X\varrho      &\X\chi         \\
\X\varepsilon   &\X\mu          &\X\sigma       &\X\psi         \\
\X\zeta         &\X\nu          &\X\varsigma    &\X\omega       \\
\X\eta          &\X\xi                                          \\
                                                                \\
\X\Gamma        &\X\Lambda      &\X\Sigma       &\X\Psi         \\
\X\Delta        &\X\Xi          &\X\Upsilon     &\X\Omega       \\
\X\Theta        &\X\Pi          &\X\Phi
\end{tabular}
\caption{Greek Letters}\label{greek}
\end{table}

ou

\begin{equation}
x^3 =\int_{0}^{\infty} f(x,y) dy
\end{equation}
  • et encore

    $$x^3 =\int_{0}^{\infty} f(x,y) dy + c$$
    

inline

Because people requested an easier way to enter latex, I've added the possibility to write $ ... $ to obtain inline formulas. This is equivalent to writing \$ ...\$ and has the same single-line limitation (but everything else isn't really useful in formulas anyway). In order to do this, install the inline\_latex.py parser add #format inline\_latex to your page (alternatively, configure the default parser to be ``inline\_latex). This parser accepts all regular wiki syntax, but additionally the $ ... $' syntax. Additionally, the ``inline_latex` formatter supports $$....$$ style formulas (still limited to a single line though!) which puts the formula into a paragraph on its own.

Note: in the nikola blog, this is directly accomplished by using ReST : \$\\lambda\$ = $lambda$

Comments

2010-06-24 installing SUMATRA

2010-06-24 13:36:57
  • notes from the CodeJamNr4
  • this was using a fresh install of ETS 6.2

dependencies

  • pysvn :

    • had to uninstall stuff from MacPorts

      sudo port uninstall --follow-dependents subversion
      
    • get pysvn

      • make :

        cd Source
        python setup.py backport
        Create the Makefile using python setup.py configure
        make
        
    • install

      sudo rsync -av pysvn /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/
      
      • pysvn 1.7.1 worked for me
  • mercurial

    sudo easy_install mercurial
    
  • django

    sudo easy_install django django_tagging
    

with hg

525  svn export ../sci/dyva/Motion/particles hg_particles
526  cd hg_particles/
527  hg init
528  hg add MotionParticles.py experiment_all.py
529  hg commit
530  hg commit -m 'test'
531  echo $USER
532  vim .hgrc
533  vim ~/.hgrc
534  hg commit -m 'my first HG commit'
535  vim ~/.hgrc
536  ipython
537  ls
538  smt init sumatraTest_hg
539  smt info

with svn

 501  cd sci/dyva/Motion/particles/
 502  smt init -h
 503  smt init sumatraTest
 504  smt info
511  smt configure --simulator=python --main=experiment_all.py
 512  smt info
 513  smtweb &
 514  ls -a
 515  rm -fr .smt
 516  smt init sumatraTest
 517  smtweb &
 518  open experiment_all.py
 519  touch fake.param
 520  smt run
 521  smt run -s python -m experiment_dot.py fake.param
 522  smt info
 523  smt configure -h
 524  smt configure -c diff
 525  smt info
 526  smt run -s python -m experiment_dot.py fake.param
 529  smt run -s python -m experiment_dot.py fake.param
 534  rm mat/dot.npy
 535  python experiment_dot.py fake.param
 536  ls
 537  smt help configure
 538  smt configure -d ./figures/
 539  smt info
 540  smt configure -s python -m experiment_dot.py
 541  smt run fake.param
 542  rm mat/dot.npy
 543  smt run fake.param
 544  ls figures/
 545  rm figures/dot_*
 546  smt run fake.param
 547  smt info
 548  smt configure -d ./figures
 549  smt info
 550  rm figures/dot_*png
 551  smt configure -d ./figures
 552  smt run fake.param
 553  smt comment "apparently, it is worth NaN shekels."
 554  smt tag codejam
 558  rm figures/dot_*png
 559  rm mat/dot.npy
 560  smt run --reason="test effect of a bigger dot" fake.param dot_size=0.1
 561  ls
 562  ls -al .smt/
 563  less .smt/simulation_records
 564  sqlite3 .smt/simulation_records

Comments

2010-05-27 NeuroCompMarseille 2010 Workshop

Computational Neuroscience: From Representations to Behavior

Second NeuroComp Marseille Workshop

Date
27-28 May 2010
Location
Amphithéâtre Charve at the Saint-Charles' University campus - Métro : Line 1 et 2 (St Charles), a 5 minute walk from the railway station. Map (Amphithéâtre Charve, University Main Entrance, etc.) Metro, Bus and Tramway Getting to Marseille from Airport
Registration
Registration was free but mandatory, participation limited to 80 persons.

Computational Neuroscience emerges now as a major breakthrough in exploring cognitive functions. It brings together theoretical tools that elucidate fundamental mechanisms responsible for experimentally observed behaviour in the applied neurosciences. This is the second Computational Neuroscience Workshop organized by the "NeuroComp Marseille" network.

It will focus on latest advances on the understanding of how information may be represented in neural activity (1st day) and on computational models of learning, decision-making and motor control (2nd day). The workshop will bring together leading researchers in these areas of theoretical neuroscience. The meeting will consist of invited speakers with sufficient time to discuss and share ideas and data. All conferences will be in English.

  • 27 May 2010 Neural representations for sensory information & the structure-function relation

In this talk, I will review recent works on the sparse representations of natural images. I will in particular focus on both the application of these emerging models to image processing problems, and their potential implication for the modeling of visual processing. Natural images exhibit a wide range of geometric regularities, such as curvilinear edges and oscillating textures. Adaptive image representations select bases from a dictionary of orthogonal or redundant frames that are parameterized by the geometry of the image. If the geometry is well estimated, the image is sparsely represented by only a few atoms in this dictionary. On an ingeniering level, these methods can be used to enhance the resolution of super-resolution inverse problems, and can also be used to perform texture synthesis. On a biological level, these mathematical representations share similarities with low level grouping processes that operate in areas V1 and V2 of the visual brain. We believe both processing and biological application of geometrical methods work hand in hand to design and analyze new cortical imaging methods.

  • 11h00-12h00 Jean Petitot Centre d'Analyse et de Mathématique Sociales, Ecole des Hautes Etudes en Sciences Sociales - Paris «Neurogeometry of visual perception»*

In relation with experimental data, we propose a geometric model of the functional architecture of the primary visual cortex (V1) explaining contour integration. The aim is to better understand the type of geometry algorithms implemented by this functional architecture. The contact structure of the 1-jet space of the curves in the plane, with its generalization to the roto-translation group, symplectifications, and sub-Riemannian geometry, are all neurophysiologically realized by long-range horizontal connections. Virtual structures, such as illusory contours of the Kanizsa type, can then be explained by this model.

  • 14h00-14h45 Peggy Series Institute for Adaptive and Neural Computation, Edinburgh «Bayesian Priors in Perception and Decision Making»

We'll present two recent projects:

The first project (with M. Chalk and A. R. Seitz) is an experimental investigation of the influence of expectations on the perception of simple stimuli. Using a simple task involving estimation and detection of motion random dots displays, we examined whether expectations can be developed quickly and implicitly and how they affect perception. We find that expectations lead to attractive biases such that stimuli appear as being more similar to the expected one than they really are, as well as visual hallucinations in the absence of a stimulus. We discuss our findings in terms of Bayesian Inference.

In the second project (with A. Kalra and Q. Huys), we explore the concepts of optimism and pessimism in decision making. Optimism is usually assessed using questionnaires, such as the LOT-R. Here, using a very simple behavioral task, we show that optimism can be described in terms of a prior on expected future rewards. We examine the correlation between the shape of this prior for individual subjects and their scores on questionnaires, as well as with other measures of personality traits.

  • 14h45-15h45 Heiko Neumann (in collaboration with Florian Raudies) Inst. of Neural Information Processing, Ulm University Germany «Cortical mechanisms of transparent motion perception – a neural model»

Transparent motion is perceived when multiple motions different in directions and/or speeds are presented in the same part of visual space. In perceptual experiments the conditions have been studied under which motion transparency occurs. An upper limit in the number of perceived transparent layers has been investigated psychophysically. Attentional signals can improve the perception of a single motion amongst several motions. While criteria for the occurrence of transparent motion have been identified only few potential neural mechanisms have been discussed so far to explain the conditions and mechanisms for segregating multiple motions. A neurodynamical model is presented which builds upon a previously developed neural architecture emphasizing the role of feedforward cascade processing and feedback from higher to earlier stages for selective feature enhancement and tuning. Results of computational experiments are consistent with findings from physiology and psychophysics. Finally, the model is demonstrated to cope with realistic data from computer vision benchmark databases. Work supported by European Union (project SEARISE), BMBF, and CELEST

  • 16h00-17h00 Rudolf Friedrich Institute für Theoretische Physik Westfälische Wilhelms Universität Münster ** «Windows to Complexity: Disentangling Trends and Fluctuations inComplex Systems»**

In the present talk, we discuss how to perform an analysis of experimental data of complex systems by disentangling the effects of dynamical noise (fluctuations) and deterministic dynamics (trends). We report on results obtained for various complex systems like turbulent fields, the motion of dissipative solitons in nonequilibrium systems, traffic flows, and biological data like human tremor data and brain signals. Special emphasis is put on methods to predict the occurrence of qualitative changes in systems far from equilibrium. [1] R. Friedrich, J. Peinke, M. Reza Rahimi Tabar: Importance of Fluctuations: Complexity in the View of stochastic Processes (in: Springer Encyclopedia on Complexity and System Science, (2009))

  • 17h00-17h45 General Discussion
  • 28 May 2010 Computational models of learning and decision making
  • 9h30-10h00 Andrea Brovelli Institut de Neurosciences Cognitives de la Méditerranée, CNRS and Université de la Méditerranée - Marseille «An introduction to Motor Learning, Decision-Making and Motor Control»
  • 10h00-11h00 Emmanuel Daucé Mouvement & Perception, UMR 6152, Faculté des sciences du sport «Adapting the noise to the problem : a Policy-gradient approach of receptive fields formation»

In machine learning, Kernel methods are give a consistent framework for applying the perceptron algorithm to non-linear problems. In reinforcement learning, the analog of the perceptron delta-rule is called the "policy-gradient" approch proposed by Williams in 1992 in the framework of stochastic neural networks. Despite its generality and straighforward applicability to continuous command problems, quite few developments of the method have been proposed since. Here we present an account of the use of a kernel transformation of the perception space for learning a motor command, in the case of eye orientation and multi-joint arm control. We show that such transformation allows the system to learn non-linear transformation, like the log-like resolution of a foveated retina, or the transformation from a cartesian perception space to a log-polar command, by shaping appropriate receptive fields from the perception to the command space. We also present a method for using multivariate correlated noise for learning high-DOF control problems, and propose some interpretations on the putative role of correlated noise for learning in biological systems.

  • 11h00-12h00 Máté Lengyel Computational & Biological Learning Lab, Department of Engineering, University of Cambridge «Why remember? Episodic versus semantic memories for optimal decision making»

Memories are only useful inasmuch as they allow us to act adaptively in the world. Previous studies on the use of memories for decision making have almost exclusively focussed on implicit rather than declarative memories, and even when they did address declarative memories they dealt only with semantic but not episodic memories. In fact, from a purely computational point of view, it seems wasteful to have memories that are episodic in nature: why should it be better to act on the basis of the recollection of single happenings (episodic memory), rather than the seemingly normative use of accumulated statistics from multiple events (semantic memory)? Using the framework of reinforcement learning, and Markov decision processes in particular, we analyze in depth the performance of episodic versus semantic memory-based control in a sequential decision task under risk and uncertainty in a class of simple environments. We show that episodic control should be useful in a range of cases characterized by complexity and inferential noise, and most particularly at the very early stages of learning, long before habitization (the use of implicit memories) has set in. We interpret data on the transfer of control from the hippocampus to the striatum in the light of this hypothesis.

  • 14h00-15h00 Rafal Bogacz Department of Computer Science, University of Bristol «Optimal decision making and reinforcement learning in the cortico-basal-ganglia circuit»

During this talk I will present a computational model describing decision making process in the cortico-basal ganglia circuit. The model assumes that this circuit performs statistically optimal test that maximizes speed of decisions for any required accuracy. In the model, this circuit computes probabilities that considered alternatives are correct, according to Bayes’ theorem. This talk will show that the equation of Bayes’ theorem can be mapped onto the functional anatomy of a circuit involving the cortex, basal ganglia and thalamus. This theory provides many precise and counterintuitive experimental predictions, ranging from neurophysiology to behaviour. Some of these predictions have been already validated in existing data and others are a subject of ongoing experiments. During the talk I will also discuss the relationships between the above model and current theories of reinforcement learning in the cortico-basal-ganglia circuit.

  • 15h30-16h30 Emmanuel Guigon Institut des Systèmes Intelligents et de Robotique, UPMC - CNRS / UMR 7222 «Optimal feedback control as a principle for adaptive control of posture and movement»
  • 16h30-17h15 General Discussion

Comments

2010-05-23 Haïm Cohen : Tu Ne Laisseras Point Pleurer

2010-05-23 11:04:50

http://ecx.images-amazon.com/images/I/31Rx4loOyhL._SL500_AA300_.jpg

  • Présentation de l'éditeur (source: amazon)
    • Où puiser l'espoir d'un monde plus humain ? En comprenant la dimension humaine des pleurs de nos bébés et en y répondant encore et encore. A partir d'arguments psychologiques et neurobiologiques, Haïm Cohen nous expose son utopie susceptible d'élever la conscience morale de nos enfants ainsi immunisés contre l'extrême violence. Manuel d'humanisme autant que de réflexion portée sur notre société, ce livre s'adresse à tous les parents soucieux du bon développement psycho-affectif de leur enfant, mais aussi à tous les lecteurs intéressés par les progrès des neurosciences.
    • Biographie de l'auteur : Haïm Cohen est pédiatre à Paris.
  • utopie de base: importance de ne pas laisser un bébé pleurer, ce qui amènerait le bébé à accepter le manque et la violence entre individus. peut se baser sur notre évolution à l'échelle du million d'année, notre statut ancien de chasseur / cueilleur. les pleurs sont universels, un langage "phasique" primaire, primal
  • convergence de la "neuroanalyse" : psychanalyse + neuroscience ...
  • vers une émergence de l'éthique. l'individu n'a qu'un objectif d'épanouissement personnel. perception de l'altruisme, émergence de l'éthique depuis l'interaction de ces individualités.

Comments

2010-04-28 reStructuredText rst cheatsheet

2010-04-28 10:15:04
  • http://docutils.sourceforge.net/docs/user/rst/cheatsheet.txt

  • =====================================================
     The reStructuredText_ Cheat Sheet: Syntax Reminders
    =====================================================
    :Info: See <http://docutils.sf.net/rst.html> for introductory docs.
    :Author: David Goodger <goodger@python.org>
    :Date: $Date: 2006-01-23 02:13:55 +0100 (Mon, 23 Jän 2006) $
    :Revision: $Revision: 4321 $
    :Description: This is a "docinfo block", or bibliographic field list
    
    Section Structure
    =================
    Section titles are underlined or overlined & underlined.
    
    Body Elements
    =============
    Grid table:
    
    +--------------------------------+-----------------------------------+
    | Paragraphs are flush-left,     | Literal block, preceded by "::":: |
    | separated by blank lines.      |                                   |
    |                                |     Indented                      |
    |     Block quotes are indented. |                                   |
    +--------------------------------+ or::                              |
    | >>> print 'Doctest block'      |                                   |
    | Doctest block                  | > Quoted                          |
    +--------------------------------+-----------------------------------+
    | | Line blocks preserve line breaks & indents. [new in 0.3.6]       |
    | |     Useful for addresses, verse, and adornment-free lists; long  |
    |       lines can be wrapped with continuation lines.                |
    +--------------------------------------------------------------------+
    
    Simple tables:
    
    ================  ============================================================
    List Type         Examples
    ================  ============================================================
    Bullet list       * items begin with "-", "+", or "*"
    Enumerated list   1. items use any variation of "1.", "A)", and "(i)"
                      #. also auto-enumerated
    Definition list   Term is flush-left : optional classifier
                          Definition is indented, no blank line between
    Field list        :field name: field body
    Option list       -o  at least 2 spaces between option & description
    ================  ============================================================
    
    ================  ============================================================
    Explicit Markup   Examples (visible in the `text source <cheatsheet.txt>`_)
    ================  ============================================================
    Footnote          .. [1] Manually numbered or [#] auto-numbered
                         (even [#labelled]) or [*] auto-symbol
    Citation          .. [CIT2002] A citation.
    Hyperlink Target  .. _reStructuredText: http://docutils.sf.net/rst.html
                      .. _indirect target: reStructuredText_
                      .. _internal target:
    Anonymous Target  __ http://docutils.sf.net/docs/ref/rst/restructuredtext.html
    Directive ("::")  .. image:: images/biohazard.png
    Substitution Def  .. |substitution| replace:: like an inline directive
    Comment           .. is anything else
    Empty Comment     (".." on a line by itself, with blank lines before & after,
                      used to separate indentation contexts)
    ================  ============================================================
    
    Inline Markup
    =============
    *emphasis*; **strong emphasis**; `interpreted text`; `interpreted text
    with role`:emphasis:; ``inline literal text``; standalone hyperlink,
    http://docutils.sourceforge.net; named reference, reStructuredText_;
    `anonymous reference`__; footnote reference, [1]_; citation reference,
    [CIT2002]_; |substitution|; _`inline internal target`.
    
    
    Directive Quick Reference
    =========================
    See <http://docutils.sf.net/docs/ref/rst/directives.html> for full info.
    
    ================  ============================================================
    Directive Name    Description (Docutils version added to, in [brackets])
    ================  ============================================================
    attention         Specific admonition; also "caution", "danger",
                      "error", "hint", "important", "note", "tip", "warning"
    admonition        Generic titled admonition: ``.. admonition:: By The Way``
    image             ``.. image:: picture.png``; many options possible
    figure            Like "image", but with optional caption and legend
    topic             ``.. topic:: Title``; like a mini section
    sidebar           ``.. sidebar:: Title``; like a mini parallel document
    parsed-literal    A literal block with parsed inline markup
    rubric            ``.. rubric:: Informal Heading``
    epigraph          Block quote with class="epigraph"
    highlights        Block quote with class="highlights"
    pull-quote        Block quote with class="pull-quote"
    compound          Compound paragraphs [0.3.6]
    container         Generic block-level container element [0.3.10]
    table             Create a titled table [0.3.1]
    list-table        Create a table from a uniform two-level bullet list [0.3.8]
    csv-table         Create a table from CSV data (requires Python 2.3+) [0.3.4]
    contents          Generate a table of contents
    sectnum           Automatically number sections, subsections, etc.
    header, footer    Create document decorations [0.3.8]
    target-notes      Create an explicit footnote for each external target
    meta              HTML-specific metadata
    include           Read an external reST file as if it were inline
    raw               Non-reST data passed untouched to the Writer
    replace           Replacement text for substitution definitions
    unicode           Unicode character code conversion for substitution defs
    date              Generates today's date; for substitution defs
    class             Set a "class" attribute on the next element
    role              Create a custom interpreted text role [0.3.2]
    default-role      Set the default interpreted text role [0.3.10]
    title             Set the metadata document title [0.3.10]
    ================  ============================================================
    
    Interpreted Text Role Quick Reference
    =====================================
    See <http://docutils.sf.net/docs/ref/rst/roles.html> for full info.
    
    ================  ============================================================
    Role Name         Description
    ================  ============================================================
    emphasis          Equivalent to *emphasis*
    literal           Equivalent to ``literal`` but processes backslash escapes
    PEP               Reference to a numbered Python Enhancement Proposal
    RFC               Reference to a numbered Internet Request For Comments
    raw               For non-reST data; cannot be used directly (see docs) [0.3.6]
    strong            Equivalent to **strong**
    sub               Subscript
    sup               Superscript
    title             Title reference (book, etc.); standard default role
    ================  ============================================================
    
  • results in

The reStructuredText Cheat Sheet: Syntax Reminders

Info: See <http://docutils.sf.net/rst.html> for introductory docs.
Author: David Goodger <goodger@python.org>
Date: $Date: 2006-01-23 02:13:55 +0100 (Mon, 23 Jän 2006) $
Revision: $Revision: 4321 $
Description: This is a "docinfo block", or bibliographic field list

Section Structure

Section titles are underlined or overlined & underlined.

Body Elements

Grid table:

Paragraphs are flush-left, separated by blank lines.

Block quotes are indented.

Literal block, preceded by "::":

Indented

or:

> Quoted
>>> print 'Doctest block'
Doctest block
Line blocks preserve line breaks & indents. [new in 0.3.6]
Useful for addresses, verse, and adornment-free lists; long lines can be wrapped with continuation lines.

Simple tables:

List Type Examples
Bullet list
  • items begin with "-", "+", or "*"
Enumerated list
  1. items use any variation of "1.", "A)", and "(i)"
  2. also auto-enumerated
Definition list
Term is flush-left : optional classifier
Definition is indented, no blank line between
Field list
field name: field body
Option list
-o at least 2 spaces between option & description
Explicit Markup Examples (visible in the text source)
Footnote
[1] Manually numbered or [#] auto-numbered (even [#labelled]) or [*] auto-symbol
Citation
[CIT2002] A citation.
Hyperlink Target
Anonymous Target
Directive ("::") images/biohazard.png
Substitution Def
Comment
Empty Comment (".." on a line by itself, with blank lines before & after, used to separate indentation contexts)

Inline Markup

emphasis; strong emphasis; interpreted text; interpreted text with role; inline literal text; standalone hyperlink, http://docutils.sourceforge.net; named reference, reStructuredText; anonymous reference; footnote reference, [1]; citation reference, [CIT2002]; like an inline directive; inline internal target.

Directive Quick Reference

See <http://docutils.sf.net/docs/ref/rst/directives.html> for full info.

Directive Name Description (Docutils version added to, in [brackets])
attention Specific admonition; also "caution", "danger", "error", "hint", "important", "note", "tip", "warning"
admonition Generic titled admonition: .. admonition:: By The Way
image .. image:: picture.png; many options possible
figure Like "image", but with optional caption and legend
topic .. topic:: Title; like a mini section
sidebar .. sidebar:: Title; like a mini parallel document
parsed-literal A literal block with parsed inline markup
rubric .. rubric:: Informal Heading
epigraph Block quote with class="epigraph"
highlights Block quote with class="highlights"
pull-quote Block quote with class="pull-quote"
compound Compound paragraphs [0.3.6]
container Generic block-level container element [0.3.10]
table Create a titled table [0.3.1]
list-table Create a table from a uniform two-level bullet list [0.3.8]
csv-table Create a table from CSV data (requires Python 2.3+) [0.3.4]
contents Generate a table of contents
sectnum Automatically number sections, subsections, etc.
header, footer Create document decorations [0.3.8]
target-notes Create an explicit footnote for each external target
meta HTML-specific metadata
include Read an external reST file as if it were inline
raw Non-reST data passed untouched to the Writer
replace Replacement text for substitution definitions
unicode Unicode character code conversion for substitution defs
date Generates today's date; for substitution defs
class Set a "class" attribute on the next element
role Create a custom interpreted text role [0.3.2]
default-role Set the default interpreted text role [0.3.10]
title Set the metadata document title [0.3.10]

Interpreted Text Role Quick Reference

See <http://docutils.sf.net/docs/ref/rst/roles.html> for full info.

Role Name Description
emphasis Equivalent to emphasis
literal Equivalent to literal but processes backslash escapes
PEP Reference to a numbered Python Enhancement Proposal
RFC Reference to a numbered Internet Request For Comments
raw For non-reST data; cannot be used directly (see docs) [0.3.6]
strong Equivalent to strong
sub Subscript
sup Superscript
title Title reference (book, etc.); standard default role

Comments

2010-04-26 replacing text in files

2010-04-26 12:17:16

using sed

  • The UNIX command sed is useful to find and replace text in single or multiple files. This page lists some common commands in using sed to improve editing code.

  • To replace foo with foo_bar in a single file:

    sed -i 's/foo/foo_bar/g' my_script.py
    
    • -i = edit the file "in-place": sed will directly modify the file if it finds anything to replace
    • s = substitute the following text
    • foo = the text string to be substituted
    • foo_bar = the replacement string
    • g = global, match all occurrences in the line
  • To replace foo with foo_bar in multiple files:

    sed -i 's/foo/foo_bar/g'  *.py
    
  • Consult the manual pages of the operating system that you use: mansed

  • in the particular case of changing a scaling parameter in a set of experiment files:

    sed -i 's/size = 6/size = 7/g'  experiment*.py
    sed -i 's/size = 7/size = 6/g'  experiment*.py
    

using vim

  • on the current buffer, with confirmation

    :%s/old_text/new_text/cg
    
  • on the current buffer

    :%s/old_text/new_text/g
    
  • to get help

    :help substitute
    
  • one could pass the required files to 'args' and apply whatever command to all these files using the command 'argdo'. First I will apply the substitute 's' command and then 'update' which will only save the modified files.

    :args *.py
    :argdo :%s/old_text/new_text/g | update
    

Comments