sábado, 31 de agosto de 2013

Progress Report Update

This weeks I have been working on how to providing initial data for our models. I thought that use a dictionary type could be an easy way. But it isn't... I want to preserve the order of inserted data, nor store the data sorted by the key (as dictionary type do)!
But, after hours of pain, something came to my rescue : a dictionary that remembers insertion order! From python 2.7, OrderedDict is supported [1].
This example will show you a quick idea of how it works:

Case 1: numbers for dict keys 

>>> from collections import OrderedDict
>>> from pprint import pprint
>>> 
>>> V = {
...     '1': ['time',  'cost'],
...     '2': ['time',  'cost'],
...     '3': ['time'],
...      }
>>>      
... pprint (V)
{'1': ['time', 'cost'], '2': ['time', 'cost'], '3': ['time']}
>>> 
>>> V = OrderedDict((
...         ('1', ['time',  'cost']),
...         ('2', ['time',  'cost']),
...         ('3', ['time'])
...         ))
>>> pprint (V)
OrderedDict([('1', ['time', 'cost']), ('2', ['time', 'cost']), ('3', ['time'])])
Case 2: strings for dict keys 

>>> from collections import OrderedDict
>>> from pprint import pprint
>>> 
>>> V = {
...     'train': ['time',  'cost'],
...     'bus':   ['time',  'cost'],
...     'car':   ['time'],
...      }
>>> pprint (V)
{'bus': ['time', 'cost'], 'car': ['time'], 'train': ['time', 'cost']}
>>> 
>>> V = OrderedDict((
...         ('train', ['time',  'cost']),
...         ('bus',   ['time',  'cost']),
...         ('car',   ['time'])
...         ))
>>> pprint (V)
OrderedDict([('train', ['time', 'cost']), ('bus', ['time', 'cost']), ('car', ['time'])])
While in case 1 (dictionary keys with numbers) the outcome is similar, with strings for dictionary keys (case 2), it isn't: only the order is preserved for ordered dictionary.

[1] https://pypi.python.org/pypi/ordereddict

lunes, 19 de agosto de 2013

Progress Report

This weeks I made a results class, some tests and examples for the Conditional Logit Model. The model has some dirty code and some hacks, so, I've to work on it this week. On the other hand I was working simultaneously on the Nested Logit Model but, so far, only a draft in the paper.

One interesting thing learned: how to rename a file with git.

  • There is a rename command (git mv): 
git mv <oldname>  <newname>
  • Note that the effect is the same from removing the file and adding another with different name and the same content.
  • This command is also use to move file from one to another location:
git mv <source> <destination>


One interesting thing found:
A useful git visual cheatsheet: http://ndpsoftware.com/git-cheatsheet.htm

And one motivate thing! we received a message on the statsmodels mailing list being interested in the Conditional Logit model. He gave us some tricks for the implementation and offered as beta tester! That was wonderful!

jueves, 1 de agosto de 2013

Quick status - Plans for Next Weeks

This weeks I've been working on a type of Multinomial Logit Model which variables could vary over alternatives. That model is also called conditional logit model.
You can view the code on my github: https://github.com/AnaMP/statsmodels/compare/clogit

The next couple of weeks are going to be spent working on the Nested Logit Model. The model is the same as conditional logit excepted that captures correlations between alternatives by partitioning the choice set into nests.

I'll write about this in more detail next weeks on the statsmodels wiki:

Stay tuned!