Arithmetic / Statistical Mode in C#

August 17, 2008 01:39 by frank

So recently, I needed a method to give me a statistical (or arithmetic) mode of an array of numbers. I searched the internet for a breif moment and didn't find any pre-coded solutions in C# so I just wrote my own. The following is that method. Two things to note, it uses generics so it works equally well for an int array or a double array, et cetera. Also, it will find a mode not all modes for a given array. You'd have to modify the method to return all (and I just needed one for my application).

If I did something silly, feel free to let me know.

public static T GetStatisticalMode(T[] array) {
Dictionary dictionary = new Dictionary();
// get a count of how often each item in the array occurs
foreach (T item in array) {
if (dictionary.ContainsKey(item)) {
dictionary[item] = dictionary[item] + 1;
} else {
dictionary.Add(item, 1);
}
}
// get the first largest mode encountered
int largestOccurance = 0;
T largestOccuranceKey = dictionary.Keys.GetEnumerator().Current;
foreach (T key in dictionary.Keys) {
if (dictionary[key] > largestOccurance) {
largestOccurance = dictionary[key];
largestOccuranceKey = key;
}
}
return largestOccuranceKey;
}

eMusic Downloads for August 2008

July 25, 2008 09:24 by frank

 

 

New Look

July 24, 2008 09:36 by frank

The website has a new look. It's very "green". It seems to work for both Firefox (3) and Internet Explorer (7) as well as Safari (3 - Windows). Let me know if there's any issues.

Remedy

September 26, 2007 16:06 by frank

 

 

Well I did two things I haven't done in a while!

I bought a CD that wasn't through eMusic! 

Instead I used Amazon's new music download service. I bought David Crowder*Band's new CD, Remedy. It meets all my ethical requirements for music it's at 320 bit rate, it's in non-DRMed mp3 format, and I love the label that DC*B belongs to enough to want them to get some of my money. Oh, and it was $1 cheaper than iTunes! Amazon claims that "most" albums are between 5.99 and 9.99. This particular CD was only 8.99. I'll take that extra dollar any day. The CD could have used a couple more tracks though. Ten tracks, although rather common, is a few too short for a full CD in my opinion.

I bought a Christian CD!

I'm generally not a fan of Christian music. I have nothing against the "Christian" part of it--it's the "music" part I'm not a fan of. For one, most Christian music seems to fall into the "Pop" type category which I'm not a big fan of (I'm of course generalizing a bit). It's also (understandably) all about the same thing. Some musicians don't seem to be skillful enough (or not desire) to make it non-monotonous in content. Additionally, it's just so clean--and I'm not referring to language. I can't find much Christian music with any real "grit" to it. The lyrics are very much on the "sunny side of life", the music is smooth and predictable and the vocalist always seems to come straight from church choir. That's probably fine for most people but I'm the guy who has said things like "Man, that guy cannot sing at all but I love this album!". 

There are some Christian artists that I have immense respect for but I don't long to listen to their music (e.g. Michael W. Smith [Although his instrumental album is wonderful], Steven Curtis Chapman), there are others that I listened to in youth and respect and enjoy their music (e.g. DC Talk, Caedmon's Call, Jars of Clay), and more than a few more that I can't find much good in their music at all. As new music coming from those bands I respected and enjoyed waned, I started giving up on Christian music to fulfill my music desire. 

I have to point out that I'm now very out of touch with the Christian music scene. DC*B is one of the few Christian artists I still keep up with. I absolutely love DC*B. I hope I haven't horribly miss-represented the current Christian music scene just because I can't find good stuff out there. Like the genre of Hip-Hop, I assume there is quality music out there but it eludes me. It's my fault for that.

As a side note, why is it I only get the overwelming urge to blog when I really have other things I need to be doing? I have two mid-terms tomorrow for goodness sake! 

eMusic Downloads for September 2007

September 4, 2007 18:34 by frank

Well I succumbed to temptation and upgraded my eMusic subscription to the full 75 songs. It's only $20 bucks a month so I still consider it a good deal. Because one album is a large 24 song album, I still only got 5 albums this month. One of the groups is from Athens, Georgia (my new home) and another is from the Elephant 6 Recording Company which is (sorta) based in Athens as well. There are two more albums from the US's large northern neighbor and one from the US's parent country.

Artist: The Real Tuesday Weld
Album: The London Book of the Dead
Release Date: August 28, 2007
eMusic Genre: Indie Pop
Total Songs: 16

Described as british old-timey electro pop, I really like this artist.


Artist: Octoberman
Album: Run From Safety
Release Date: August 21, 2007
eMusic Genre: Indie Rock
Total Songs: 10

More music from dirty Canada :).



Artist: The Apples in Stereo
Album: New Magnetic Wonder
Release Date: Feburary 06, 2007
eMusic Genre: Indie Rock
Total Songs: 24

Associated with the wonderful Elephant 6 Recording Co. Really good feeling album.


Artist: Casper & The Cookies
Album: The Optimist's Club
Release Date: August 29, 2006
eMusic Genre: Indie Rock
Total Songs: 11

This Athens, Ga, based band gives us a nice cheesy shot of optimism.


Artist: Shapes and Sizes
Album: Split Lips, Winning Hips, A Shiner
Release Date: May 22, 2007
eMusic Genre: Indie Pop
Total Songs: 14

The sophomore album from another group of Canadians. 


I'm very happy with how these are turning out so far. The Real Tuesday Weld's album is another really good album (I loved their first) and The Apples In Stereo are always great.

eMusic Downloads for August 2007

July 31, 2007 08:46 by frank

  This months theme isn't really a theme at all. Actually it's just me downloading everything I can find from the canadian indie band Stars. I'm planning to see them perform in Atlanta in October so I'll be very familiar with them by then. 

Artist: Stars
Album: In our Bedroom after the War
Release Date: September 25, 2007
eMusic Genre: Indie Rock
Total Songs: 13, Total Songs Left: 37

This is the "advance" release. It won't be in stores until September 25 but it's available for digital 


Artist: Stars
Album: In our Bedroom after the War
Release Date: February 27, 2001
eMusic Genre: Indie Rock
Total Songs: 14, Total Songs Left: 23

The first release from the group. Some say their best.



Artist: Stars
Album: Heart
Release Date: February 11, 2003
eMusic Genre: Indie Rock
Total Songs: 14, Total Songs Left: 12

Described as an "electro-pop Belle & Sebastian".


Artist: Spoon
Album: Ga Ga Ga Ga Ga
Release Date: July 10, 2007
eMusic Genre: Indie Rock
Total Songs: 10, Total Songs Left: 2

To round it all out, I had to get the newest release from Spoon, amazingly titled "Ga Ga Ga Ga Ga".


Once again I've to figure out what on earth to do with 2 downloads left. The per song download has to be the biggest draw back of eMusic. But hey, 4 new albums for $15 (that's $3.75 each) is too good to pass up I guess.