Natural Code

Code, science and politics.

Fire Katie Couric (hire a journalist instead)

Someone should lose their job over this, anyways. Here’s a brief timeline for those of us who are temporal-perception-impaired.

September 2006 : The Anbar Salvation Council is formed. This is known as the beginning of the Sunni Awakening, in which a majority of Anbari tribes aligned themselves with the American and Iraqi government forces and began fighting against Al-Quaeda.

January 2007 : Bush announces an increase in US troop levels in Iraq. This increase becomes known as the surge. Notice that this happens after the Awakening.

“So I’ve committed more than 20,000 additional American troops to Iraq,” says Bush, while US troop levels are slightly over 130,000.

March 2007 : US troop levels pass the 140,000 mark.

April 2007 : US troop levels pass the 150,000 mark. The surge troops Bush announced in January have mostly arrived.

July 21, 2008 : Barack Obama claims that the troop surge is not the only factor contributing to reduced violence in Iraq, saying it’s also because of “political factors inside Iraq that came right at the same time as terrific work by our troops.”

July 22, 2008 : Katie Couric interviews John McCain. She asks him for his response to Obama’s statement on the surge and reduced violence.

McCain claims (this is from the CBS transcript) that “Because of the surge we were able to go out and protect that sheik and others. And it began the Anbar awakening. I mean, that’s just a matter of history.” That’s right, he’s claiming that the 2007 troop surge caused a 2006 event.

Katie Couric, apparently as unaware as McCain that in this universe cause generally comes before effect, fails to call him on it. She follows up this complete fabrication, and the rest of his rambling Abe Simpson response, with the question “A commentary on what?”

You see, the last word in McCain’s answer was ‘commentary’, so she just asked him to explain that word. Hard-hitting journalism!

CBS news sensed that they were on to a big story about a presidential candidate’s lack of foreign policy knowledge and problems understanding how time works. They did the only thing they could as responsible journalists : they replaced McCain’s ridiculous answer with the answer to a completely different question.

McCain’s explanation of imaginary history was replaced by one of his canned slogans. And they aired it that way. CBS’s response?

“The report was edited under extreme time constraints and one piece of tape was put in the wrong order. Fortunately, this did not in any way distort what Senator McCain was saying.”

Bullshit. They didn’t just distort what he said, they replaced it with a fictional response that meant something completely different, in order to make him look better.

At best, it’s some incredibly lousy journalism.

July 24, 2008 Posted by naturalcode | Uncategorized | , , , , , , , , , | 2 Comments

Sixty-nine fascists : there’s still one place where the majority will defend Bush.

Tuesday night on Countdown, Rachel Maddow talked to Jonathan Turley, professor of constitutional law. The professor had this to say about the Democrats’ capitulation on the FISA bill :

“So, what the Democrats are doing here with the White House is they‘re trying to conceal a crime that is hiding in plain view, that everyone can see it.  And so, the argument for it is quite sill simple, nobody wants to have a confrontation over the fact that the president committed a felony, not once, but at least 30 times.  That‘s a very inconvenient fact right now in Washington.”

“I think that the founders would have found this incomprehensible.  The expanse of power to the point of including what is now defined as a federal crime.  And not only that, but the Democrats have learned well from Bush.

Because the telecoms are losing in court, because the administration is losing in court, they‘re just going to change the rules, so that these public interest organizations that have brought these cases will all lose by a vote to fiat by the Democrats.  It‘s otherworldly.”

MADDOW:  “Senator Obama says he does not like this bill, but he says he‘s supporting it as a compromise.  Is this a compromise?  Is that the right term for it?  Is he right?”

TURLEY:  “Yes.  I got to tell you, I am completely astonished by Senator Obama‘s position and obviously disappointed.  You know, all of these senators need to respect us enough, not to call it a compromise.  It‘s a cave-in.”

TURLEY:  “And, you know what‘s terrible is like one of those stories where someone is assaulted on a street and a hundred witnesses do nothing.  And in this case, the Fourth Amendment is going to be eviscerated tomorrow.  And 100 people are going to watch it happen because it‘s just not their problem.

But you talk about expanding the president‘s power, it‘s coming out of the marrow of the Fourth Amendment.  It‘s coming out of the bone.  And it‘s going to hurt.  And it‘s being done for political convenience.  There‘s not an ounce of principle, not an ounce of public interest in this legislation.

So, at least show us respect of not calling it a compromise.”

Amen. Calling it a compromise is an insult to Americans on top of the injury to the Constitution. Yesterday was a terrible day for freedom and justice, and the cowards that let this happen in a Democrat-controlled Senate need to be called out.

One more reason to use encryption wherever we can. If only Tor was faster.

July 10, 2008 Posted by naturalcode | Uncategorized | , , , , , , , , | 3 Comments

Data streams, part 1

American Scientist has an article in their latest issue that talks about the algorithmic difficulties of processing streams of data. It begins by talking about how search engines identify the most popular people (“The Britney Spears problem”), and then goes on to use simple number streams to explain the subject.

I was making progress in reading the article, when I got sidetracked by this :

Although identifying the most frequent item in a stream is hard in general, there is an ingenious way of doing it in one special case—namely, when the most common item is so popular that it accounts for a majority of the stream entries (more than half the elements).

The algorithm that accomplishes this task requires just two registers, and it runs in a constant amount of time per stream element. (Before reading on you might want to try constructing such an algorithm for yourself.)

This is where I put down the magazine, opened SciTE, and wrote this :

require 'stream_algorithm'

reader = StreamReader.new
reader.check :total_amount, :biggest_element

stream = NumberStream.new( reader ).start

The code for the required ’stream_algorithm’ file is at the end of this post. When I run this, I get output that looks like this :

Starting streamreader...
Stream running!
Reading : 8
Reading : 8
Reading : 6
Reading : 4
Reading : 5
Reading : 8
Reading : 2
Reading : 6
Reading : 2
Reading : 8
Stream stopped.
Total amount : 10
Biggest element : 8

Cool. Now I’ve got a simple way of testing and playing with the concepts in the article. Next I’ll try to make the stream reader keep track of the most frequent number using only two numerical variables.

To be continued.

Here’s the code for the NumberStream and StreamReader classes.

#stream_algorithm.rb
def force string
  puts string
  STDOUT.flush
end

class NumberStream
  attr_reader :length, :reader

  def initialize reader, length=10
    @reader = reader
    @length = length
  end

  def start
    force "Stream running!"

    1.upto(length) { next_number }; stop
  end

  def stop
    force "Stream stopped."
    reader.display_results
  end

  def next_number
    reader.send rand( 10 )
    sleep 0.1
  end
end

class StreamReader
  attr_accessor :to_check

  def initialize
    force "Starting streamreader..."
  end

  def send element
    force "Reading : #{element}"
    process element
  end

  def check *args
    @to_check = args
    @to_check.each { |thing| eval "@#{thing} = 0" }
  end

  def process element
    if to_check.include? :total_amount
      @total_amount += 1
    end

    if to_check.include? :biggest_element
      @biggest_element = element if @biggest_element < element
    end
  end

  def display_results
    to_check.each do |thing|
      display_name = thing.to_s.capitalize.gsub( /_/, ' ' )
      variable = eval "@#{thing}"

      force "#{display_name} : #{variable}"
    end
  end
end

July 6, 2008 Posted by naturalcode | Uncategorized | , , , | 1 Comment

LAGWAGON, MxPx, Only Crime, and TAT – Rimouski September 8th

Nick says go see Lagwagon in Rimouski on September 8th with MxPx, Only Crime, and TAT.

Ça va rocker en tabarnack.

July 6, 2008 Posted by naturalcode | Uncategorized | , , , , , , , | No Comments Yet

“John McCain” “Google hacking” “level of expertise”

Last night on Countdown, Rachel Maddow commented on John McCain’s latest lie about one of his previous lies.

“John McCain continues to deny he has ever downplayed his economic know-how, is he familiar with the Google?” she wondered.

Let’s see what the Google has to say about that.

Oh, look. An older video of all the Republican candidates being asked whether they used a PC or a Mac. John McCain’s response? “Neither. I am… I am a… illiterate that has to rely on my wife for all of the assistance that I can get.”

Guess not, Rachel.

July 4, 2008 Posted by naturalcode | Uncategorized | , , , , , , , | No Comments Yet

Tracking the trackers

The University of Washington study on the methods used by anti-piracy organizations to find copyright violations has a sample DMCA takedown notice, received by the University during the study, from which they’ve removed the names and addresses. After a few paragraphs of legal threats, the letter contains this gem :

” Further, we believe that the entire Internet community benefits when these matters are resolved cooperatively. We urge you to take immediate action to stop this infringing activity and inform us of the results of your actions. We appreciate your efforts toward this common goal. “

For people who are paid to spy on and denounce other people’s Internet use, they seem pretty clueless.

Hello, recording industry, and welcome to the 21st century. It’s not called ARPANET anymore, Internet users aren’t an obscure subculture, my dog has a website, and people don’t buy CDs. This is the world you live in, and it’s too late to prevent what’s already happened.

Not that we’d want to, anyways. Most of us don’t own a record label with an anachronistic business model.

June 29, 2008 Posted by naturalcode | Uncategorized | , , , | No Comments Yet

“Why My Printer Received a DMCA Takedown Notice”

Oh, this is good. The University of Washington Department of Computer Science and Engineering recently released a study investigating the methods used by anti-piracy organizations to find people who share copyrighted material.

During their investigation, they received hundreds of legal threats in the form of DMCA takedown notices, despite never having shared any actual copyrighted material. Some of these threats involved alleged copyright violations by things like networked printers supposedly hosting movies.

Of course, the people/spambots who work for these anti-piracy organizations don’t need anything resembling proof before they threaten legal action. When you don’t care about serious investigation and your only concern is meeting your Bad Guy quota, the throw-’em-all-in-Gitmo approach works fine.

In any case, no law needs to have been broken before these people try to confuse a judge into ordering a teenager to pay thousands of dollars to their multinational media company. All they need is two things.

A string of text like “Iron_Man-(2008).[xvid].ScrEEnEr”, and the most ruthless lawyer goons that a bottomless wallet can buy.

June 27, 2008 Posted by naturalcode | Uncategorized | , , , | No Comments Yet

A basic genetic algorithm (part 3)

I’ve posted the updated code here, on Refactor :my => ‘code’, a cool little site I just found.

I’ll go refactor someone else’s code on there later, could help me with my coding too.

The program works now, although it’s not too efficient. I need to add sexual reproduction, ’cause right now they’re asexual and that’s slower.

EDIT: Okay, I’ll just leave it up on the other site then, because WordPress was throwing HTML in my Ruby, like this :

def initialize(copy_genome=‘off’ <img src=“http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif” alt=“;)” class=“wp-smiley”>

June 8, 2008 Posted by naturalcode | Uncategorized | , , , , | No Comments Yet

A basic genetic algorithm (part 2)

Okay, so I’ve broken this up into two files :

equation.rb

class Array
  def random
    self[rand(self.length)]
  end
end

class Genome
  attr_accessor :code

  @@decode = {   '0000' => '0.0', '0001' => '1.0',
  '0010' => '2.0', '0011' => '3.0', '0100' => '4.0',
  '0101' => '5.0', '0110' => '6.0', '0111' => '7.0',
  '1000' => '8.0', '1001' => '9.0', '1010' => '+',
  '1011' => '-', '1100' => '*', '1101' => '/' }
  @@operators = %w[+ - * /]
  @@numbers = %w[0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0]

  def initialize(min_length=4, max_length=32)
    length = min_length + rand(1 + max_length - min_length)
    @code = generate_code(length)
  end

  def generate_code(length)
    code = ''
    1.upto(length) do
      code += ['0', '1'].random
    end
    code
  end

  def decode
    decoded = ''
    expected = :number

    1.upto(@code.length) do |i|
      if i % 4 == 0
        coded = @code.slice((i-4)..(i-1))
        symbol = @@decode[coded].to_s
        puts symbol
        if expected == :number && @@numbers.include?(symbol)
          decoded += symbol
          expected = :o perator
        elsif expected == :o perator &&
        @@operators.include?(symbol)
          decoded += symbol
          expected = :number
        else
          puts "#{expected} expected, #{symbol} found."
        end
      end
    end

    if expected == :number
      decoded.chop!
    end

    return decoded
  end
end

class Equation
  attr_accessor :genome, :phenotype

  def initialize
    @genome = Genome.new(4, 64)
    @phenotype = @genome.decode
  end
end

formula_ga.rb

require 'equation'

class Population
  def initialize(size=50, target_number=11)
    @equations = []
    @size = size
    @target_number = target_number
    1.upto(size) { @equations << Equation.new }
  end

  def members
    @equations
  end

  def evaluate_fitness(equation)
    answer = eval(equation.phenotype)
    deviation = @target_number - answer.to_f
    fitness = 1 / deviation
  end

  def sort_by_fitness(equation_array)

  end

  def next_generation
    reproduction_pool = []
    1.upto(@size / 2) do
      reproduction_pool << @equations.random
    end
  end
end

pop = Population.new
pop.members.each do |member|
  puts member.genome.code
  puts member.phenotype
  x = eval(member.phenotype)
  puts x.to_s
  puts "Fitness : #{pop.evaluate_fitness(member)}"
  puts ""
end

June 7, 2008 Posted by naturalcode | Uncategorized | , , , , | No Comments Yet

First post!

This is going to be a place where I talk about things like coding, natural languages, and genetics. Read the tagline already. More to come.

June 3, 2008 Posted by naturalcode | Uncategorized | | No Comments Yet