Friday, August 31, 2012

Progressively distributed RGB colors.


    public int getColor(int index) {
        int[] p = getPattern(index,0);
        return getElement(p[0]) << 16 | getElement(p[1]) << 8 | getElement(p[2]);
    }
Fetching routine.

    public int getElement(int index) {
        int value = index - 1;
        int v = 0;
        for (int i = 0; i < 8; i++) {
                v = v | (value & 1);
                v <<= 1;
                value >>= 1;
        }
        v>>=1;
        return v & 0xFF;
    }
    It turns out to make numbers that go 255, 0, 128, 192, 64, ... it's just counting upwards and then flipping the order of the bits to being a big endian things rather than a small endian order. Starting from -1 rather than zero.


The only thing left is to pattern these numbers progressively. So everything with 0, then all permutations with 1, then all permutations with 2, then all permutations with 3 ect. There's bound to be a more elegant way to this than the way I did it but:
  
    public int[] getPattern(int index, int n) {
        int[] p = new int[3];
        if (index - 1 < 0) {
            Arrays.fill(p,n);
            return p;
        }
        index -= 1;
        for (int q = 0; q < 3; q++) {
            if (index - n < 0) {
                Arrays.fill(p,n);
                p[q] = index;
                return p;
            }
            index -= n;
        }
        for (int q = 0; q < 3; q++) {
            if (index - (n*n) < 0) {
                boolean d = true;
                for (int m = 0; m < 3; m++) {
                    if (m == q) p[m] = n;
                    else if (d) {
                        d = false;
                        p[m] = index / n;
                    }
                    else {
                        p[m] = index % n;
                    }
                }
                return p;
            }
            index -= (n * n);
        }
        return getPattern(index,n+1);
    }
    Which then cycles through producing first black then, every color 256 bits from black (namely white), then all the colors patterns with these bits, then adding in 128 and all the color patterns with that in the mix. Etc. Calling it recursively because apparently I'm a balla (an inelegant one at that).

It might be better to just normalize the values there and feed them into something like LAB skipping imaginary colors etc.

Update:
If you are going to use this code, for whatever reason:
see the improved getPattern routine.

http://godsnotwheregodsnot.blogspot.com/2012/09/color-distribution-sans-recursion.html

Thursday, August 30, 2012

anti-gray code fragment.


Given some index,

        int antigray;
        int vp = index >> 1;
        antigray = vp ^ (vp >> 1);
        antigray <<= 1;
        if ((index & 1) == 1) antigray ^= -1;

Produces a unique antigray code. There's likely going to be a simpler solution somewhere. Rather than shifting right, gray coding, shifting left, and inverting due to the original bit. But, it's the code solution to my Anti-Gray Codes and a pretty easy couple lines. And having found out that I needed something else for the question I was answering, I cut this bit, and didn't really want to lose it.

There are other gray codes than index ^ (index >> 1) but that's a really good derivation. My solution works for any gray codes. So this shouldn't be taken as the only optimally distant code. Also, there might be more distance possible between step-2 codes. It's maximally distant hamming distance is only for the very next and just previous code. But, the code after the next code, may end up being very similar to the current code. Solving for a code giving the maximally distant hamming distance beyond absolutely adjacent codes might not even be derivable through my method. Though, assuming one doesn't weight the code requirements such that step-2 codes being very maximally different could trump some slightly closer step-1 codes. The hamming distance pattern would be N, N-1, N, N-1 ... to which the anti-code would have to be a gray code.

The most distant step-2 code segments would require that with a hamming distance of 1, the same bit not be modified until all other bits are modified.

So the gray code to derive this would be something like:
0000
0001 -- bit 1.
0011 -- bit 2.
0111 -- bit 3
1111 -- bit 4
1110 -- bit 1 - 4 distance.
1100 -- bit 2 - 4 distance.
1000 -- bit 3 - 4 distance.
1001 -- bit 1 - 3 distance.
1011 -- bit 2 - 3 distance.
1010 -- bit 1 - 2 distance (this might be an error).
0010 -- bit 4 - 7 distance.
0110 -- bit 3 - 5 distance.
0100 -- bit 2 - 4 distance.
0101 -- bit 1 - 4 distance.
1101 -- bit 4 - 4 distance.

Which would then derive to several different gray codes which should still have 1 hamming distance between step-2 codes, but hamming distances of 2 for step-4 codes. Though, it would have less hamming distance at step-3 codes, which may defeat the entire purpose and depending on how much more you value step codes from one another. But, maximizing step-4 and step-6 codes may well minimize step-3 and step-5 codes.  But,  should at the very least it should maintain a hamming distance above 2 for step-2, and step-3 and potentially step-4 codes, and maximally distant codes at step-1.


Tuesday, August 21, 2012

Is there a God? Can poor arguments convince you?

http://www.everystudent.com/features/isthere.html?gclid=CNOh74Wc-LECFWjhQgodoSgA_A

Is there a God? Here's six terrible and mostly wrong arguments that can be easily dissected and shown wrong.

1) Does God exist? We aren't dead.
2) Does God exist? Science has a gap. *not really a gap
3) Does God exist? Science has a gap. *not really a gap
4) Does God exist? I don't understand evolution.
5) Does God exist? You're reading this and must be interested therefore God wants you to come to him.
6) Does God exist? The Bible.

Friday, August 17, 2012

Anti-gray codes. How to derive them.

Do you need a series such that the next item in the series has the maximum amount of bits different from the previous one. You need an anti-gray code. Gray codes are codes like that where the next digit only varies by 1. To make an anti gray code:


Take any gray code. Shift all the bits to the left by 1. Double the list. And alternate XOR flips. Done. You have an anti-gray code.

Take gray code.
0
1

Shift all the bits to the left by 1.
00
10

Double the list.
00
00
10
10

Alternate XOR flips.
00
11
10
01

The reason this works is because gray codes by definition have the minimal amount of distance. Xor flips have the maximum (they flip every bit). If you interweave them you will have maximum, maximum -1, maximum, maximum -1, maximum, maximum -1... which is an optimal anti-gray code. Also note, you don't really *need* to shift the bits to the left. You can introduce a zero *anywhere*, so long as you do it consistently. Watch, I'll do it with the middle digit.



     00,01,11,10
-> 000,001,101,100
-> 000,000,001,001,101,101,100,100
-> 000,111,001,110,101,010,100,011 (perfect anti-grey code).

Update:
Source fragment if you just want blackbox code.

Wednesday, August 15, 2012

I'm not blogging that much.

This is news that must be put on my blog post haste.

Monday, July 30, 2012

On human brains and that spark of magic, and why cars don't think.

Why should your car have a mind? Rocks and doors and dressers don't have minds either. There are very few things in this world that are not brains that appear to have minds. Your ideas, hopes, dreams, goals, personality, quirks, attitude, etc. can all be traced down to that skullful of neurons between your ears. Every last iota of who you are, and who you think you are. And there's not one iota of a fragment of a supposition that says otherwise. Yes, your brain tries to predict the future, and when it does and it gets a right answer (which is much easier to verify than arrive at) you get intuitive leaps and profound insight. It's one thing to have a big idea explained to you and understanding it, it's another thing to get there yourself. "The answer just came to me." It didn't come from magical elves or gods, it came from you. They always do. You think therefore you are, but moreover you are your thinking. Is it really unfathomable that the most complicated machine we've ever encountered anywhere, the most advanced brain with symbolic thinking and the entire corpus of humanity's ideas and frameworks and language that came before cannot possibly come up with something new that isn't delivered from on high by magic?

I am in awe of the brain. I try to understand to comprehend to gather how it works and the more you learn about it the more amazing you find it to be. It may have quirks and illusions; it's fantastic to be sure. It's not some vital element of magical intuition that gives you that human spark. It's not some implausible ephemera, or phantasmagorical pneuma, it's actually you. You. You actually kick that much ass and are actually that awesome made out of water, fat, protein, and bone. And while cognitive biases will always tell you that you can't just be made out of natural normal stuff, we can trace down those thoughts and it's all being thunk on natural normal stuff and nothing magical or unreal. It isn't that cars lack a vital element but cars lack a human brain, and you don't... you are a human brain. No gods required.

Wednesday, July 25, 2012

On Quantum Brains Freeing you from Determinism.

With QM we could build robots that could have non-deterministic brains. Whose choices cannot be predicted before hand but which are randomized by quantum particles. You *STILL* don't want to be that robot! This isn't really what you want.

Saturday, July 14, 2012

Crash Course Awesome



Wow.

Ssnot RSS Feed is stuck

So nobody reading this through RSS will know. How strange.

Wednesday, July 11, 2012

Emotional Lures.

The lack of emotional pleas is one of the serious problems with atheism's PR. It only has the honest truth as a selling point. And it's not very effective. If you can promise people infinite happiness, love of their family, specialness in the universe, and safety from infinite torture (which is the *only* other alternative). You will certainly catch more flies. You will always catch more flies with honey than vinegar, even if the honey is a comforting lie invented to lure and the vinegar is both real and incredibly useful.

Friday, July 6, 2012

On the citations of famous people to prove a reality helping people out.

For any person we've heard of, events conspired to make them who they are. That's because we've heard of them. They are a self-selected sample. Really there's a lot of people we've never heard of who died in a ditch.

Friday, June 29, 2012

I keep forgetting the word leitmotif.

It's starting to annoy me. It's one of those very useful words that refer to something specific that just slips my mind when I want to use it. I also recently forgot the word Procrustean much to my dismay. I'm tempted to use ixperienceness at some point but I think the one place I saw it made it up "I experience ness".

Tuesday, June 26, 2012

That was quick.

I went from think that's stupid to oh, hm, that's right in about 3 seconds.

Researcher argues that plants see.

What, plants don't have eye... --  “A plant sees what we see. A plant sees light.” -- Oh, wait, plants are all about the light, and the direction it comes from and moving towards it and smelling particular things and communicating. So much for my eye ball fetish. If you have a bunch of leaves I don't see how I can't accept that they are a massive number of light sensing organs.
ZOMG, an atheist blogger I've never heard of decided that a malformed question was too hard to answer and converted to Christianity.

This made the news.

There's a reason why this makes the news. It's man bites dog. Serious, religious person becomes an atheist. That happens all the time. Most atheists *ARE* former religious people. That's dog bites man. But, an atheist become Christian that's dog bites man. It's rare and it's rare for a reason. Religion (yours included) typically looks obviously wrong from the outside. So RA's conversion, or Patrick Greene's half conversion, or Flew's descent into dementia, actually gets some coverage because it's a rare enough event to care about, but only because Christianity is wrong enough to make it that rare.

In short, though this seems like a win for Christianity. The fact that it's report worthy is a failure for Christianity. It shows how rare your successes are. It's like that time when the Iraq war had zero US soldier casualties for a month. The fact that that got reported, is actually, viewed in a larger context a bad thing overall.

Thursday, June 21, 2012

Why are nigeria scammers upfront with the whole they are Nigerian Scammers thing?

http://research.microsoft.com/pubs/167719/WhyFromNigeria.pdf

The bad spelling, the claiming to be from Nigeria thing, this is suppose to reduce false-positives. The last thing they want are people who are fooled enough by the well done font and professional looking design and the seemingly legit promises to respond initially and then take up their very real time and then balk at the part where you wire money to Nigeria. It turns out if you make it obvious, only the very very stupid will respond, and that's exactly the target demographic.

Wow. I wouldn't have thought of that.

Tuesday, June 19, 2012

Of suns and designers.

“It's natural to think that living things must be the handiwork of a designer. But it was also natural to think that the sun went around the earth. Overcoming naive impressions to figure out how things really work is one of humanity's highest callings.  (Can You Believe in God and Evolution? Time Magazine, August 7, 2005)” ― Steven Pinker

I see the sun it's like two inches wide. The earth is all around us and doesn't move. That stupid bright spot spends all day moving. It's obvious why people think the sun moves around the Earth, because it's obvious!

Now, why is it that evolved natural-selected things look so much like the handiwork of a designer? Why is that view the naive view. We can concede it's both the naive view and the wrong answer, but why are humans so inclined to think it's the right answer. What's the two-inch dot vs. panorama of planet reason why we think design is a good explanation for life, even if we scientifically know it's Darwin all the way back?

Monday, June 18, 2012

I'm excessively proud of this...

In reference to my propensity to argue with wrong people for a long time, a comparison was made to Don Quixote.

"I'm quite quixotic like that. I see a what may be a wayward intellectual giant that I can help, so I tilt my sharp wit and pointed remarks at what inevitably turns out to be a grinding experience by something dumb as a rock and powered by hot air."
 You see, it's making the whole attacking giants which turn out to be windmills thing into a parallel statement. It's overly impressive. Especially because I fear it will fall flat. 

Monday, June 11, 2012

Oh My Darling Clementine

Final Stanza

How I missed her, how I missed her,
How I missed my Clementine,
Til I kissed her little sister,
And forgot my Clementine.

Friday, June 8, 2012

How Absurd and Scary (more Java coding).

I wrote a class that scares me. It makes nodes into widgets and calls itself recursively.

import java.awt.Image;
import java.awt.Point;
import java.beans.BeanInfo;
import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.Action;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import org.netbeans.api.visual.action.ActionFactory;
import org.netbeans.api.visual.action.PopupMenuProvider;
import org.netbeans.api.visual.layout.LayoutFactory;
import org.netbeans.api.visual.widget.Scene;
import org.netbeans.api.visual.widget.Widget;
import org.netbeans.api.visual.widget.general.IconNodeWidget;
import org.openide.nodes.*;
import org.openide.util.Lookup;
import org.openide.util.lookup.Lookups;

public class NodeWidget extends IconNodeWidget implements PopupMenuProvider, Lookup.Provider, NodeListener {
    Node node;
    boolean vertical;
    public NodeWidget(Scene scene, Node node) {
        this(scene,node,true);
    }
   
    private NodeWidget(Scene scene, Node node, boolean vertical) {
        super(scene);
        this.vertical = vertical;
        this.node = node;
        Image icon = node.getIcon(BeanInfo.ICON_COLOR_32x32);
        if (icon != null) {
            getImageWidget().setImage(icon);  
        }
        getLabelWidget().setLabel(node.getDisplayName());
        if (vertical) {
            this.setLayout(LayoutFactory.createVerticalFlowLayout());
        }
        else {
            this.setLayout(LayoutFactory.createHorizontalFlowLayout());
        }
        if (node.getActions(false) != null) {
            getActions().addAction(ActionFactory.createPopupMenuAction(this));
        }
        refreshChildren();
        node.addNodeListener(this);
    }

    @Override
    public Lookup getLookup() {
        return Lookups.proxy(node);
    }

    @Override
    public JPopupMenu getPopupMenu(Widget widget, Point point) {
        JPopupMenu pop = new JPopupMenu();
        for (Action action : node.getActions(false)) {
            pop.add(action);
        }
        return pop;
    }
   
    private Collection childnodewidgets = new ArrayList<>();
    private void refreshChildren() {
        if (!SwingUtilities.isEventDispatchThread()) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    refreshChildren();
                }
            });
            return;
        }
        for (Widget widget : childnodewidgets) {
            widget.revalidate();
            widget.removeFromParent();
            revalidate();
        }
        childnodewidgets.clear();
        Widget widget;
        if (!node.isLeaf()) {
            Children c = node.getChildren();
            for (Node n : c.getNodes()) {
                widget = new NodeWidget(getScene(), n, !vertical);
                childnodewidgets.add(widget);
                addChild(widget);
                widget.revalidate();
                revalidate();
            }
        }
        getScene().validate();
    }

    @Override
    public void childrenAdded(NodeMemberEvent nme) {
        refreshChildren();
    }

    @Override
    public void childrenRemoved(NodeMemberEvent nme) {
        refreshChildren();
    }

    @Override
    public void childrenReordered(NodeReorderEvent nre) {
        refreshChildren();
    }

    @Override
    public void nodeDestroyed(NodeEvent ne) {
       removeChildren();
       removeFromParent();
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
    }
   
}


 That's spooky. And looks terrible-ish. I'll remove that recursive children part and actually use it. But, it uses Virtual Library and cross connects Netbeans display Nodes. I dragged a directory out of favorites (and had an AcceptAction in the scene to grab nodes) and the sucker did an entire directory display all over the place.

Wednesday, May 30, 2012

On God and How I already know.

>>You know that God exists.

God is about as absurd as elves or unicorns. More even.

>>You want to fight that truth with everything you can,

Fight what truth? All religions make contradictory claims with the same quality of evidence. Why should I accept the Jewish Scape-goat blood sacrifice God of Jesus any more than the Norse collect you from the battle field God of Odin? It's culture invented deities. They don't actually make sense. Why should Odin send Valkyries to collect you from the battlefield? Isn't that just a cultural way to make people fight harder? Why should God sacrifice himself to himself? Isn't that just Jewish scapegoating and blood sacrifice to atone for sins. These aren't ways the universe should actually work. These are ways that primitive people would invent.


>>but it doesn't change the fact that He has made it obvious to anyone who doesn't intentionally blind themselves to it,

By providing better natural answers for everything?

>>and you know it to be true.

I think it's silly. It's hard pressed to suppose that that is me knowing that Allah is God or that the blood of Zalmoxis will make me live forever.

>>You also know that God has a moral standard to which he holds humanity accountable.

According to the Bible, women are chattel, and slavery is fine, and killing people for minor crimes is great. Picking up sticks on a Sunday is as great of a crime as murdering your father on a Monday. You only really use your own moral standard. And it's an insult to such a moral standard to credit your God with it. Your God would burn Gandhi in hell forever for failing to accept Jesus as his personal Lord and Savior. Gandhi gets eternal torture for a thought crime.


>>Your own conscience tells you this to be true, and also tells you that you've failed to live up to it.

It really doesn't. Anymore than shaving makes me feel that I have changed Allah's creation.


>>There's nothing more I can do to show you these things - you already know them.

These things being the standards of your God? Which suggest that twice as sinful to have a female child as a male child, or that burnt flesh is pleasing to God? Or that God so loved me that he murdered his child, because apparently killing things is some kind of forgiveness. Which it clearly isn't but it's pretty clear why first century Jewish culture might think so.

>>If you continue to walk in willful blindness of the obvious truth,

I cannot express how honestly I think your religion is stupid.


>>then you'll unfortunately have to accept the consequences of denying that truth.

Eternal torment from a loving God, for thought crimes of not believing. Because when Hitler burns Anne Frank for being Jewish we say that he is evil, but when God burns Anne Frank forever for being Jewish that makes him good? That eternal torment is the just desserts for Gandhi or Buddha. Such absurdity should shock the mind of even a child.


>>For your sake, I pray that you won't suppress the truth for the rest of your life. If you take your last breath in this life without repenting and believing in God, it will be too late. And you'll regret it for eternity.

And if you fail to accept Allah, and put partners unto Allah, he will mock you and then send you to hell. Such silly bits of threats of eternal phantorment do not make a good argument. If your God would eternally punish people for finite crimes, he is evil. If your God would eternally torture people for thought crimes, he is absurd. Your religion worships a tyrant in the sky, revels in the blood of his dead son, because culturally sacrificing living things to God to achieve forgiveness made sense to goat herders in the ancient middle east, but in this day and age... wake up!


>>Please, listen to reality. Please, listen to your conscience. Please, listen to truth.

Ditto.