|
1 | | -'''Vowel evolution program. |
2 | | -Run with Vowel, Convention, Game_fns, Agent, Word |
3 | | -Import Vowel |
4 | | -Last update March 2016 HJMS''' |
5 | | - |
6 | | -import Vowel |
7 | | - |
8 | | -class Prototype(Vowel.Vowel): |
9 | | - '''Prototype class *Vowel subclass* |
10 | | - A Prototype indicates the average f1/f2 position, length of a vowel |
11 | | - and the number of carriers (Agents) |
12 | | - i.e. the conventional representation of a vowel for some population. |
13 | | - Prototypes are formed by collecting Vowels from agents. ''' |
14 | | - |
15 | | - def __init__(self, e1, e2, length, name): |
16 | | - super(Prototype, self).__init__(e1, e2, length, name) |
17 | | - self.carriers = 1 #some assumed agent not in population (so it's never 0) |
18 | | - |
19 | | - def __str__(self): |
20 | | - '''shown as '(f1, f2, length, carriers)' |
21 | | - NOTE: STR and REPR use HZ as INTS for first formant, second formant, |
22 | | - where everything else is in ERB units as FLOATS''' |
23 | | - f1, f2 = self.to_hz_praat(self.e1, self.e2) |
24 | | - f1 = int(f1) |
25 | | - f2 = "{:>4}".format(int(f2)) |
26 | | - l = int(self.length) |
27 | | - s = "({0}, {1}, {2})".format(f1, f2, l) |
28 | | - return s |
29 | | - |
30 | | - def __repr__(self): |
31 | | - '''shown as 'f1_hz, f2_hz, length' ''' |
32 | | - e1 = self.e1 |
33 | | - e2 = self.e2 |
34 | | - repr_s = ", ".join( [ str(e1), str(e2), str(self.length)] ) |
35 | | - return '('+repr_s+')' |
36 | | - |
37 | | - def to_hz_praat(self, e1, e2): |
38 | | - '''Traunmuller formula used in Praat software''' |
39 | | - from math import exp |
40 | | - d1 = exp ((e1 - 43.0) / 11.17) |
41 | | - f1 = (14680*d1 - 312.0) / (1 - d1) |
42 | | - |
43 | | - d2 = exp ((e2 - 43.0) / 11.17) |
44 | | - f2 = (14680*d2 - 312.0) / (1 - d2) |
45 | | - return (f1, f2) |
46 | | - |
47 | | - def __eq__(self, other): |
48 | | - matches = (self.e1 == other.e1 and |
49 | | - self.e2 == other.e2 and |
50 | | - self.length == other.length) |
51 | | - return matches |
52 | | - |
53 | | - def update(self, ne1, ne2, nl, c): |
54 | | - ''' |
55 | | - overwrite formant values (e.g. to update mean centers) |
56 | | - ''' |
57 | | - self.e1 = ne1 |
58 | | - self.e2 = ne2 |
59 | | - self.length = nl |
60 | | - self.carriers = c |
61 | | - |
62 | | - def __hash__(self): |
63 | | - '''use e1 (float), e2 (float) and length (int)''' |
64 | | - return hash((self.e1, self.e2, self.length)) |
| 1 | +'''Vowel evolution program. |
| 2 | +Run with Vowel, Convention, Game_fns, Agent, Word |
| 3 | +Import Vowel |
| 4 | +Last update March 2016 HJMS''' |
| 5 | + |
| 6 | +import Vowel |
| 7 | + |
| 8 | +class Prototype(Vowel.Vowel): |
| 9 | + '''Prototype class *Vowel subclass* |
| 10 | + A Prototype indicates the average f1/f2 position, length of a vowel |
| 11 | + and the number of carriers (Agents) |
| 12 | + i.e. the conventional representation of a vowel for some population. |
| 13 | + Prototypes are formed by collecting Vowels from agents. ''' |
| 14 | + |
| 15 | + def __init__(self, e1, e2, length, name): |
| 16 | + super(Prototype, self).__init__(e1, e2, length, name) |
| 17 | + self.carriers = 1 #some assumed agent not in population (so it's never 0) |
| 18 | + |
| 19 | + def __str__(self): |
| 20 | + '''shown as '(f1, f2, length, carriers)' |
| 21 | + NOTE: STR and REPR use HZ as INTS for first formant, second formant, |
| 22 | + where everything else is in ERB units as FLOATS''' |
| 23 | + f1, f2 = self.to_hz_praat(self.e1, self.e2) |
| 24 | + f1 = int(f1) |
| 25 | + f2 = "{:>4}".format(int(f2)) |
| 26 | + l = int(self.length) |
| 27 | + s = "({0}, {1}, {2})".format(f1, f2, l) |
| 28 | + return s |
| 29 | + |
| 30 | + def __repr__(self): |
| 31 | + '''shown as 'f1_hz, f2_hz, length' ''' |
| 32 | + e1 = self.e1 |
| 33 | + e2 = self.e2 |
| 34 | + repr_s = ", ".join( [ str(e1), str(e2), str(self.length)] ) |
| 35 | + return '('+repr_s+')' |
| 36 | + |
| 37 | + def to_hz_praat(self, e1, e2): |
| 38 | + '''Traunmuller formula used in Praat software''' |
| 39 | + from math import exp |
| 40 | + d1 = exp ((e1 - 43.0) / 11.17) |
| 41 | + f1 = (14680*d1 - 312.0) / (1 - d1) |
| 42 | + |
| 43 | + d2 = exp ((e2 - 43.0) / 11.17) |
| 44 | + f2 = (14680*d2 - 312.0) / (1 - d2) |
| 45 | + return (f1, f2) |
| 46 | + |
| 47 | + def __eq__(self, other): |
| 48 | + matches = (self.e1 == other.e1 and |
| 49 | + self.e2 == other.e2 and |
| 50 | + self.length == other.length) |
| 51 | + return matches |
| 52 | + |
| 53 | + def update(self, ne1, ne2, nl, c): |
| 54 | + ''' |
| 55 | + overwrite formant values (e.g. to update mean centers) |
| 56 | + ''' |
| 57 | + self.e1 = ne1 |
| 58 | + self.e2 = ne2 |
| 59 | + self.length = nl |
| 60 | + self.carriers = c |
| 61 | + |
| 62 | + def __hash__(self): |
| 63 | + '''use e1 (float), e2 (float) and length (int)''' |
| 64 | + return hash((self.e1, self.e2, self.length)) |
0 commit comments