Turtle in Python

All

2Intro

I was playing a bit on python, as usual, and I came again with the Turtle built-in module. That’s an amazing module that remembers me the good days of Logo, Rip Seymont Paper.

Turtle

Such a cool module, it’s totally underrated. Well, at least on my side. Make sure to not name the module turtle, As I did, it won’t work obviously.

import turtle

silly = turtle.Turtle()

silly.forward(50)
silly.right(90)     # Rotate clockwise by 90 degrees

silly.forward(50)
silly.right(90)

silly.forward(50)
silly.right(90)

silly.forward(50)
silly.right(90)

turtle.done()

The references can be found here [1] and some codes I’ve done can be found here [2]. It’s very simple, pretty much like logo.

Simple things like square and circles are done with just one line.

REFs

[1] https://docs.python.org/2/library/turtle.html

[2]https://github.com/FranciscoMeloJr/Python-Tests

 

Python asserts

All

Intro

I was doing some python tests recently I came to use python asserts again, np_asserts, python asserts and unittest framework. All very very useful, but I think the original assert is so clever and easy to use, we should apply them in everyday life.

asserts

  I was comparing the name of a bank (string) with the calculated value of a function that returns it.
   assert get_from_id_name_bank(‘004’) == ‘TD’
  Similar to the example in [1]

np library

Np is also so straightforward, just need to do import numpy as np and it’s done! Put the comparison, and done!

Comparing arrays for example:

      np.testing.assert_array_equal(expected,banks)
    All the supported functions are here [2].

unittest

That’s a complete framework for testing and it’s very simple and has set_up, and tear_down. All in it.

    python -m unittest -v test_module

You can add some verbosity via v while doing the execution

Source

https://github.com/FranciscoMeloJr/Python-Tests/tree/master/

REFs

[1]https://code-maven.com/slides/python-programming/pytest-compare-strings

[2]https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.testing.html

[3] https://docs.python.org/3/library/unittest.html (for python 3)

 

 

Little python exercise

All

Intro

Recently I did an interview with the following problem:

You have a list of strings, on our list, some of the strings were corrupted on the reading process. You want to avoid duplications so do an algorithm to solve this.

List example: ttoo, toto, oott.

Example output: toto.

List example 2:  xt, tx.

Example output 2: xt.

Solutions

There are several ways to solve the problem and basically, you can understand it as a sort algorithm, a kind of special sort, but a sort. Therefore a bubble sort or insertion sort can be applied.

Solution 1

My second solution was to come back to a dict and try to use it to optimize the size comparison. However, since I’m using a dict (i.e. an encoding operation) I will need therefore an operation for translate it in a list (i.e. decoding operation).

Part A – encoding:

for each_word in words:
    key = len(each_word)
    if key not in result:
        result[key] = [each_word]
    else:
        list_values = result[key]
        list_values.append(each_word)
        result[key] = list_values

Part A2: I use an aux function to end correctly in the dict

def create_new_list(list_values):
    #['ot', 'to', 'tt']
    #['to', 'tt']
    sorted(list_values)

    list_new = [list_values[0]]
    flag = True
    for i in range(1, len(list_values)):
        flag = True
        for each in list_new:
            if set(list_values[i]) == set(each):
                flag = False
        if flag:
            list_new.append(list_values[i])
    return list_new

Solution 2

This was actually my first solution on the head, but second to be implemented. And its more or less based on the insertion sort algorithm and basically inserts an element on the final list if and only if the set of this element not there.  [I mean based on insertion because you will get the elements on the list and compare with the final list.] + the survival flag for each element.

However, you still need to do the size comparison to avoid tt in ttoo problems:

flag = True
for i in range(1, len(words)):
    flag = True
    for each in final:
        if len(words[i]) == len(each) and set(words[i]) == set(each):
            flag = False
    if flag:
        final.append(words[i])
return final

The solution can be improved by using the sorted using len option (i) + the comparison is first done on the length and then on the set, avoiding unnecessary comparisons.

(i) sorted(xs, key=len)

Solution 3

Solution 3 would use a dict comprehension on the first solution. But after thinking about it, it just too noisy and unclear for the reader.

(i) I’m creating the values of the Dict on the fly, so I don’t need an extra function to do it for me (encoding).

(ii) I just put a list comprehension in the end (for the decoder operation).

(i)for each_word in words:
    key = len(each_word)
    if key not in result:
        result[key] = [each_word]
    else:
        list_values = result[key]
        # 2:[cra] - car
        for each in list_values:
            if set(each) != set(each_word):
                list_values.append(each_word)
                result[key] = list_values
(ii) return [result.get(each_key)[0] for each_key in result.keys()]

 

Solution 4

It’s totally possible to do it in just one list comprehension, though it would be very long though, basically because one would need to condense the survival code within the list comprehension. I don’t think it worth though.

Source

All the solutions are there.

https://github.com/FranciscoMeloJr/Python-Tests/tree/master/banks

REFs

[1] https://www.datacamp.com/community/tutorials/python-dictionary-comprehension

 

Reward System Studies of Video-Game Playing / Neuroscience study

All

Intro

At SMU, back in Halifax, I studied Video-games and neuroscience doing a small EEG experiment in the end. The experiment was not conclusive therefore it was not published.

Content

The full content can be found here [1], which is a report for the class in Cognitive Neuroscience 1, from Prof Jason Ivanoff.

Abstract

This review covers several studies that have measured the influence of games through
the functional Magnetic Resonance Interference – fMRI – method as a key in the effort to
understand cognitive act of game play. The reward system is the key for the understanding of videogame play, so after explaining it several studies are summarized in details with the highlights and main concepts preserved for the understanding of the current relations with games. The activations areas vmPFC, dorsal striatum, dorsal parts of the ACC, rTP, striatum, midbrain (including VTA/SN) and ventral visual stream. Moreover, several of the deactivations areas during game play are discussed: OFC, caudate nucleus, putamen and nucleus accumbens, NAc that can be very important in a cognitive perspective. Also the lack of emphasis in the NAc which plays an key role in reward system and in the impulsivity and aggression is discussed. It will also discuss tendencies considering the limitations reveled.
Keywords: fMRI, Video-Game, FPS, Reward System

REFs

[1] https://drive.google.com/file/d/0B-ZRkXDVghb6QzYxZ21jQzBGaVk/view?usp=sharing

 

PyCharm

All

Intro

My training at the bachelor level was always to avoid external help and program basically with a paper and a pen, later passing it to the computer! Mainly to avoid a lot to use unnecessary tools to do things they don’t require, trying to learn and improve yourself in a language is NOT HELPED if your IDE continue to solving all your issue.

But for improving the speed and IN REAL LIFE some tools really help, and this is the case for PyCharm! totally. Or even Microsoft VS PVT! microsoft cof cof 

PyCharm

You can find PyCharm here [1] and the download straight from the link [2]. I remember in the previous versions, back some years, it was kind of basic, nowadays though, it’s very powerful with many tools and stuff, it’s like a VS for python developers.
Remember to download/install python first, since it doesn’t come with the IDE.

I’m currently using version 2018.1.4, which is quite simple and basically plug and play. Install and run in 5 minutes.

REFs

[1] https://www.jetbrains.com/pycharm

[2] https://www.jetbrains.com/pycharm/download/download-thanks.html?platform=windows&code=PCC

Correlation does not imply causation

All

Intro

Recently I’ve come to the link [1] and it’s quite interesting and uncommon – just for funny knowledge though, nothing ext scientific.

Correlation vs Causation

I remember studying statistics at bachelor/masters and the correlation was an interesting topic for me, really.  How come two things could be so correlated but not cause the other?! But yeah. Correlation does not imply causation. The examples [1] are there to show.

My thesis

{Reminder: my thesis was about measuring performance metrics and execution of C++ programs}

Interestingly one of the bases of my master thesis is the assumption that correlation implies causation – which is quite a strong statement, but for the specific cases we deal and assuming the metrics measure all the system, we can then assume causationXcorrelation (X== implies). This is possible using the causal modal I assumed for the system [2] by the common cause principle of Reichbach [3].
It will be clearer below:

However, you can infer causality from correlation

Using a causal network, with 20 possibilities to know causality, in the model below (stolen from [2]) we assume then: (N ->) Abnormality -> Metric. The model is very useful and should it will be used for other analysis. The one I considered on the models for the metrics.

correlation

REFs

[1] http://www.tylervigen.com/spurious-correlations?fbclid=IwAR0Uz8MueFHvF994n3_sMFBzQY3IAlkUIRcuqfbyisL4doTWkzOszc3d7jM

[2] https://www.youtube.com/watch?v=HUti6vGctQM

[3] https://plato.stanford.edu/entries/physics-Rpcc/

 

 

 

Conferences

All

Intro

Although I finished my masters in 2017, in June, I still attend conferences and also send some papers for conferences I consider important – or related to what I do.
I think computer science and programming are basically an art and therefore it’s imperative to spread/share it not only with books but with our experience and contributions.

Conferences

I think is a good way to meet people, learn things and also travel to different destinations, for example, a conference in Wien (aka Viena), or Graz, or even Portugal.

I usually use Wikicfp[1] to find conferences that have some alignment with the things I usually work, for example, conferences in python or scrum.

Recently I submitted some stuff for the ECRM conference, summarizing some work I previously did as Scrum Master.

Although my passion is Latex (sharelatex/overleaf), for some conferences I develop my summaries in onedrive or google drive, so I can share with Gabriel A., since we usually work together.

REFs

[1] http://wikicfp.com/cfp/

[2] https://www.sharelatex.com/ (Legacy)

 

Duo/Trio

All

Intro

Well, I started to “play” a bit of Cajon after a show in 2011, with a saw with Yuri and Roger. The guys that were doing the songs were doing mostly covers and later let us play with the instruments.

So I found out that I really like percussion instruments and it’s great, cause that time my bass skills were not developing as fast as I thought they would.

Band

Recently I moved to Toronto, ON, from Montreal and talking with some friends here –  friend of friends too –  we got together some guys and we started to play a bit. I actually bought MY FIRST CAJON. It was great, we realized that it was missing a singer, actually, a female singer. So then, we announced on kijiji and more than two people replied!
We did some tests and essays and we are selecting our female lead singer, which will start playing with us at nights on clubs and stuff. So we might get back to Montreal just for some small demos, who knows!! We have a set with several songs in different styles.

I will keep posted about this later on!

REFs

No refs this time.