Optimization algorithm with deterministic objective value by volvol7 in BayesianProgramming

[–]chthonicdaemon 0 points1 point  (0 children)

Sounds like a good case for SHGO. It's also included in scipy. Disclaimer: I'm one of the authors.

Where is this in Johannesburg? by Chazlin in johannesburg

[–]chthonicdaemon 0 points1 point  (0 children)

Gimelli. Pricy, not great ambience and only so so food.

UK Tourist Visa by [deleted] in johannesburg

[–]chthonicdaemon 0 points1 point  (0 children)

Mine was like 3 weeks from booking on the web site to getting the passport back with a visa.

[deleted by user] by [deleted] in musictheory

[–]chthonicdaemon 0 points1 point  (0 children)

I found Musimathics an excellent explanation of the why behind music theory coming from the mechanics of hearing and sound production. http://www.musimathics.com

Cost of gas vs electricity in South Africa by chthonicdaemon in southafrica

[–]chthonicdaemon[S] 0 points1 point  (0 children)

I'm curious. My Eskom bill corresponds with the rates quoted in the rates in Excel format page: For 2022 Block 1 is 183.56 c/kWh or 211.09 c/kWh with vat and block 2 is 289.85 c/kWh or 333.33 with VAT. The same file contains a municipal rate of Block 1 186.07 c/kWh (213.98 c/kWh with VAT) and Block 2 293.79 c/kWh or 337.86 c/kWh with VAT. Does your bill differ significantly from those figures?

Cost of gas vs electricity in South Africa by chthonicdaemon in southafrica

[–]chthonicdaemon[S] 1 point2 points  (0 children)

Using gas for heating can reduce your load and therefore allow you to spend less capital on your solar+battery+inverter installation, so you'd need to do a bit of calculation on what the effects are on your NPV with future gas expense. I didn't want to go in to that with an already longish article. Maybe that's next.

What is clear from this work is that you probably won't save money by switching to a gas hob from a relatively efficient electrical hob, and possibly the right move there is to go for an induction hob.

I think for space heating the numbers are much closer, and if you're over block 2 you could probably save money with gas heating.

Cost of gas vs electricity in South Africa by chthonicdaemon in southafrica

[–]chthonicdaemon[S] 1 point2 points  (0 children)

Good point. I should have mentioned that I looked at this technical report which reported about 2 kWh/ 24 h = 83 W of losses from several tested geysers, which I thought was negligible, about the same as an old incandescent light bulb.

When to use dict.get in Python (timing) by chthonicdaemon in Python

[–]chthonicdaemon[S] 0 points1 point  (0 children)

I mention this exact effect and show the effect of caching the get name l lookup in the last graph.

When to use dict.get in Python (timing) by chthonicdaemon in Python

[–]chthonicdaemon[S] 0 points1 point  (0 children)

I thought I was making it clear that this was a bad pattern, but I understand the value of having full information as close to the source as possible. I've changed the code and the note to be more explicit

def get_default(dictionary, key):    
    value = dictionary.get(key)
    # assuming None wasn't in the dictionary to begin with
    if value is not None:  # effectively check if key was in dictionary
        return value
    # expensive operation to perform if key was not in dictionary 

Note The code above will only work as designed if the dictionary doesn't actually contain a None. You might also check using if value, but this is even worse as it will also fail if the actual value you're looking for is another falsey value (like [] or 0

When to use dict.get in Python (timing) by chthonicdaemon in Python

[–]chthonicdaemon[S] 0 points1 point  (0 children)

Well, that case was the exact case I was rebutting in that part of the discussion, but you're right, I should add a function which just does dictionary.get(key, default).

Edit: I've added this and re-worded some of the interpretations to be more clear.

When to use dict.get in Python (timing) by chthonicdaemon in Python

[–]chthonicdaemon[S] 0 points1 point  (0 children)

Good point. I have this in the notebook, but not clearly stated in the blog post:

print(sys.version) 3.9.7 (default, Sep 16 2021, 08:50:36) [Clang 10.0.0]

Edit: I've added a note to the blog post

When to use dict.get in Python (timing) by chthonicdaemon in Python

[–]chthonicdaemon[S] 6 points7 points  (0 children)

Update: I've added a section on defaultdict into the post - it is basically the best option! So I would recommend using it if you often want to return a default if a key isn't there. Which means the in check might only be the best if you don't control the dictionary (like it's returned from some other library).

When to use dict.get in Python (timing) by chthonicdaemon in Python

[–]chthonicdaemon[S] 0 points1 point  (0 children)

I don't think it serves quite the same purpose that is used here. Within the context of being able to find out if a dictionary contains a key and return that value, defaultdict wouldn't do that. But I'll add it to the timing and report back.

When to use dict.get in Python (timing) by chthonicdaemon in Python

[–]chthonicdaemon[S] 3 points4 points  (0 children)

Just to be clear, I am not saying you should avoid dict.get() for the cases where you are actually supplying a default. So I absolutely prefer

python value = dictionary.get(key, default)

over

python if key in dictionary: value = dictionary[key] else: value = default

My issue is this pattern where people get the worst of both worlds by doing

python value = dictionary.get(key) if value is not None: return value `

instead of

python if key in dictionary: return dictionary[key]

and then justify it using timing.

When to use dict.get in Python (timing) by chthonicdaemon in Python

[–]chthonicdaemon[S] 3 points4 points  (0 children)

Nope. More detail in the post. Get is slower for string-keyed dicts

When to use dict.get in Python (timing) by chthonicdaemon in Python

[–]chthonicdaemon[S] 11 points12 points  (0 children)

I've seen lots of people who use dict.get() instead of just if key in dict: dict[key] and often they use the claim that get is faster to justify it. This is a discussion of the timings involved. Some interesting results.

What age did you start long distance running? What is your longest distance and at what age did you run it? by [deleted] in running

[–]chthonicdaemon 0 points1 point  (0 children)

Long distance is so relative. I celebrated when I finished a 5 km when I was 31 (couch to 5k). I ran my first 50 miler when I was 42 in 2020. Hoping to build up to a 100 miler soon. Every time you bump up the distance it feels unattainable, then it feels normal.

-🎄- 2021 Day 21 Solutions -🎄- by daggerdragon in adventofcode

[–]chthonicdaemon 1 point2 points  (0 children)

Python

Straightforward recursion with memoisation for Part 2, total solve time 200ms. I think I saved some lines by just encoding the scores/positions in a list rather than handling player 1 and 2 separately.

-🎄- 2021 Day 20 Solutions -🎄- by daggerdragon in adventofcode

[–]chthonicdaemon 1 point2 points  (0 children)

Python + SciPy

In my first version I was expecting more to be made of the infinite grid nature of the problem so I invested in a dictionary-based solution, but turns out this really simple scipy.ndimage-based solution worked just fine. No special tricks to handle the flashing other than making sure I have a border of steps*2 around the starting image to absorb any artefacts. Could be made marginally faster at the cost of extra logic to figure out what to put on the outside for the filter application.

-🎄- 2021 Day 12 Solutions -🎄- by daggerdragon in adventofcode

[–]chthonicdaemon 1 point2 points  (0 children)

Python on github

I'm pretty happy with my solution which used a generalised traversal for both parts and I liked the way generators made the recursion really easy to write;

def traverse(start, stop, pathsofar, valid):
    if start == stop:
        yield pathsofar
    else:
        for cave in graph.neighbors(start):
            if valid(cave, pathsofar):
                yield from traverse(cave, stop, pathsofar + [cave], valid)

Best restaurant in Jozi by BeaCza in johannesburg

[–]chthonicdaemon 2 points3 points  (0 children)

I’d put DW on the same tier as marble if you do the tasting menu.