tiny | Code for 3D Reconstruction from Accidental Motion | 3D Printing library
kandi X-RAY | tiny Summary
kandi X-RAY | tiny Summary
Code for 3D Reconstruction from Accidental Motion
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of tiny
tiny Key Features
tiny Examples and Code Snippets
Community Discussions
Trending Discussions on tiny
QUESTION
Is the Shannon-Fano coding as described in Fano's paper The Transmission of Information (1952) really ambiguous?
In Detail:3 papers
Claude E. Shannon published his famous paper A Mathematical Theory of Communication in July 1948. In this paper he invented the term bit as we know it today and he also defined what we call Shannon entropy today. And he also proposed an entropy based data compression algorithm in this paper. But Shannon's algorithm was so weak, that under certain circumstances the "compressed" messages could be even longer than in fix length coding. A few month later (March 1949) Robert M. Fano published an improved version of Shannons algorithm in the paper The Transmission of Information. 3 years after Fano (in September 1952) his student David A. Huffman published an even better version in his paper A Method for the Construction of Minimum-Redundancy Codes. Hoffman Coding is more efficient than its two predecessors and it is still used today. But my question is about the algorithm published by Fano which usually is called Shannon-Fano-Coding.
The algorithm
This description is based on the description from Wikipedia. Sorry, I did not fully read Fano's paper. I only browsed through it. It is 37 pages long and I really tried hard to find a passage where he talks about the topic of my question, but I could not find it. So, here is how Shannon-Fano encoding works:
- Count how often each character appears in the message.
- Sort all characters by frequency, characters with highest frequency on top of the list
- Divide the list into two parts, such that the sums of frequencies in both parts are as equal as possible. Add the bit
0
to one part and the bit1
to the other part. - Repeat step 3 on each part that contains 2 or more characters until all parts consist of only 1 character.
- Concatenate all bits from all rounds. This is the Shannon-Fano-code of that character.
An example
Let's execute this on a really tiny example (I think it's the smallest message where the problem appears). Here is the message to encode:
ANSWER
Answered 2022-Mar-08 at 19:00To directly answer your question, without further elaboration about how to break ties, two different implementations of Shannon-Fano could produce different codes of different lengths for the same inputs.
As @MattTimmermans noted in the comments, Shannon-Fano does not always produce optimal prefix-free codings the way that, say, Huffman coding does. It might therefore be helpful to think of it less as an algorithm and more of a heuristic - something that likely will produce a good code but isn't guaranteed to give an optimal solution. Many heuristics suffer from similar issues, where minor tweaks in the input or how ties are broken could result in different results. A good example of this is the greedy coloring algorithm for finding vertex colorings of graphs. The linked Wikipedia article includes an example in which changing the order in which nodes are visited by the same basic algorithm yields wildly different results.
Even algorithms that produce optimal results, however, can sometimes produce different optimal results based on tiebreaks. Take Huffman coding, for example, which works by repeatedly finding the two lowest-weight trees assembled so far and merging them together. In the event that there are three or more trees at some intermediary step that are all tied for the same weight, different implementations of Huffman coding could produce different prefix-free codes based on which two they join together. The resulting trees would all be equally "good," though, in that they'd all produce outputs of the same length. (That's largely because, unlike Shannon-Fano, Huffman coding is guaranteed to produce an optimal encoding.)
That being said, it's easy to adjust Shannon-Fano so that it always produces a consistent result. For example, you could say "in the event of a tie, choose the partition that puts fewer items into the top group," at which point you would always consistently produce the same coding. It wouldn't necessarily be an optimal encoding, but, then again, since Shannon-Fano was never guaranteed to do so, this is probably not a major concern.
If, on the other hand, you're interested in the question of "when Shannon-Fano has to break a tie, how do I decide how to break the tie to produce the optimal solution?," then I'm not sure of a way to do this other than recursively trying both options and seeing which one is better, which in the worst case leads to exponentially-slow runtimes. But perhaps someone else here can find a way to do that>
QUESTION
I have a list of points where each point is a tiny list of size 2
. I want to sort the list of points in increasing order of x
and if x
values are equal, I break tie by sorting in decreasing order of y
.
I wrote a custom comparator to sort the points like this:
...ANSWER
Answered 2022-Mar-05 at 23:55I am missing something trivial
Method equals()
should be used for object comparison. Double equals ==
checks whether two references point to the same object in memory.
If you change the condition inside the comparator to !a.get(0).equals(b.get(0))
it will work correctly.
However, (10001, -10) was put before (10001, -8). Even though -8 is larger than -10.
The reason for such behavior is that JVM caches all the instances of Integer
(as well as Byte
, Short
and Long
) in the range [-128; 127]
. I.e. these instances are reused, the result of autoboxing of let's say int
with a value of 12
will be always the same object.
Because small values in your example like 3
, 5
, 12
will be represented by a single object, they were compared with ==
without issues. But the result of comparison with ==
for two Integer
instances with a value of 10001
will be false
because in this case there will be two distinct objects in the heap.
The approach of caching frequently used objects is called the Flyweight design pattern. It's very rarely used in Java because this pattern can bring benefits when tons of identical objects are being created and destroyed. Only in such a case caching these objects will pay off with a significant performance improvement. As far as I know, it's used in game development.
Use the power of objectsPoint
must be an object, not a list, as Code-Apprentice has pointed out in his answer. Use the power of objects and don't overuse collections. It brings several advantages:
- class provides you a structure, it's easier to organize your code when you are thinking in terms of objects;
- behavior declared inside a class is reusable and easier to test;
- with classes, you can use the power of polymorphism.
Caution: objects could be also misused, one of the possible indicators of that is when a class doesn't declare any behavior apart from getters and its data is being processed somehow in the code outside this class.
Although the notion of point (as a geometrical object) isn't complicated, there are some useful options with regard to methods. For example, you could make instances of the Point
class to be able to check to whether they are aligned horizontally or vertically, or whether two points are within a particular radius. And Point
class can implement Comparable
interface so that points will be able to compare themselves without a Comparator
.
With Java 8 method sort()
was added to the List
interface. It expects an instance of Comparator
, and if element of the list implement comparable, and you want them to be sorted according to the natural order null
can be passed as an argument.
If the specified comparator is null then all elements in this list must implement the Comparable interface and the elements' natural ordering should be used.
So instead of using utility class Collections
you can invoke method sort()
directly on a list of points (assuming that Point
implements Comparable
):
QUESTION
I'm making a polar-transformed barplot in which several of the x-axis labels overlap with the plot area. For context, I'm working on a shiny application that you can find a copy of here.
I've tried using theme(axis.text.x = element_text(vjust = -someNumber))
, but it doesn't seem to be doing anything.
Here is a reproducible example to demonstrate the problem:
...ANSWER
Answered 2022-Feb-15 at 12:27If you switch from coord_polar
to coord_curvedpolar
from the geomtextpath
package, you can have curved labels that never overlap the plotting area. The problem you describe was the main reason for writing coord_curvedpolar
in the first place.
In addition, the x axis labels are adjustable in the radial direction using the vjust
setting inside theme(axis.text.x = element_text(...))
.
No other parts of your code need to change, and the other elements of the plot are exactly the same as they would be with coord_polar
.
I think this makes for a much nicer looking plot (though I am possibly biased...)
QUESTION
how to remove that white line from a ggplot2 colourbar?
...ANSWER
Answered 2022-Feb-02 at 15:07You can set the ticks.colour=
within guide_colorbar()
by referencing via guides()
... here ya go:
QUESTION
I just started programming functionally. My current tiny project to start would be a basic pokemon battle.
Code first, explanation follows.
...ANSWER
Answered 2022-Jan-12 at 22:09Just return the result from the match
- there's no need to declare a variable:
QUESTION
I understand there are a variety of techniques for sharing memory and data structures between processes in python. This question is specifically about this inherently shared memory in python scripts that existed in python 3.6 but seems to no longer exist in 3.10. Does anyone know why and if it's possible to bring this back in 3.10? Or what this change that I'm observing is? I've upgraded my Mac to Monterey and it no longer supports python 3.6, so I'm forced to upgrade to either 3.9 or 3.10+.
Note: I tend to develop on Mac and run production on Ubuntu. Not sure if that factors in here. Historically with 3.6, everything behaved the same regardless of OS.
Make a simple project with the following python files
myLibrary.py
...ANSWER
Answered 2022-Jan-03 at 23:30In short, since 3.8, CPython uses the spawn start method on MacOs. Before it used the fork method.
On UNIX platforms, the fork start method is used which means that every new multiprocessing
process is an exact copy of the parent at the time of the fork.
The spawn method means that it starts a new Python interpreter for each new multiprocessing
process. According to the documentation:
The child process will only inherit those resources necessary to run the process object’s
run()
method.
It will import your program into this new interpreter, so starting processes et cetera sould only be done from within the if __name__ == '__main__':
-block!
This means you cannot count on variables from the parent process being available in the children, unless they are module level constants which would be imported.
So the change is significant.
What can be done?
If the required information could be a module-level constant, that would solve the problem in the simplest way.
If that is not possible (e.g. because the data needs to be generated at runtime) you could have the parent write the information to be shared to a file. E.g. in JSON format and before it starts other processes. Then the children could simply read this. That is probably the next simplest solution.
Using a multiprocessing.Manager
would allow you to share a dict
between processes. There is however a certain amount of overhead associated with this.
Or you could try calling multiprocessing.set_start_method("fork")
before creating processes or pools and see if it doesn't crash in your case. That would revert to the pre-3.8 method on MacOs. But as documented in this bug, there are real problems with using the fork
method on MacOs.
Reading the issue indicates that fork
might be OK as long as you don't use threads.
QUESTION
Beginner programmer here currently trying to learn Tkinter for a school assignment. I have a GUI class that stores the Tkinter labels etc, the labels are innitiated like this:
...ANSWER
Answered 2021-Dec-27 at 17:25The issue is self.root.update()
. Remove this line and you'll be fine.
When should I use root.update() in tkInter for python.
This is a tricky issue. Your problem come from the bind of the configure event. Bind to the root window, it is applied to all sub-widgets of the window, which cause the bug (I don't know why yet).
This will solve your issue (line 202):
QUESTION
Valgrind says the following on their documentation page
Your program is then run on a synthetic CPU provided by the Valgrind core
However GDB doesn't seem to do that. It seems to launch a separate process which executes independently. There's also no c library from what I can tell. Here's what I did
- Compile using clang or gcc
gcc -g tiny.s -nostdlib
(-g
seems to be required) gdb ./a.out
- Write
starti
- Press
s
a bunch of times
You'll see it'll print out "Test1\n" without printing test2. You can also kill the process without terminating gdb. GDB will say "Program received signal SIGTERM, Terminated." and won't ever write Test2
How does gdb start the process and have it execute only one line at a time?
...ANSWER
Answered 2021-Oct-30 at 20:48starti
implementation
As usual for a process that wants to start another process, it does a fork/exec, like a shell does. But in the new process, GDB doesn't just make an execve system call right away.
Instead, it calls ptrace(PTRACE_TRACEME)
to wait for the parent process to attach to it, so GDB (the parent) is already attached before the child process makes an execve()
system call to make this process start executing the specified executable file.
Also note in the execve(2)
man page:
If the current program is being ptraced, a SIGTRAP signal is sent to it after a successful execve().
So that's how the kernel debugging API supports stopping before the first user-space instruction is executed in a newly-execed process. i.e. exactly what starti
wants. This doesn't depend on setting a breakpoint; that can't happen until after execve anyway, and with ASLR the correct address isn't even known until after execve picks a base address. (GDB by default disables ASLR, but it still works if you tell it not to disable ASLR.)
This is also what GDB use if you set breakpoints before run
, manually, or by using start
to set a one-time breakpoint on main
. Before the starti
command existed, a hack to emulate that functionality was to set an invalid breakpoint before run
, so GDB would stop on that error, giving you control at that point.
If you strace -f -o gdb.trace gdb ./foo
or something, you'll see some of what GDB does. (Nested tracing apparently doesn't work, so running GDB under strace means GDB's ptrace system call fails, but we can see what it does leading up to that.)
QUESTION
I have written the following snippet:
...ANSWER
Answered 2021-Nov-15 at 08:50From this migration guide, the d3.event.transform
must be replaced with the following
QUESTION
I'm trying to get my image from S3 bucket and return it. Here's the code:
...ANSWER
Answered 2021-Nov-04 at 04:00Here it is how I do this:
Your lambda with corrected body
:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install tiny
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page