String filePath = new File("").getAbsolutePath();
DataSource source = new DataSource(filePath + "\\src\\data\\data.arff");
Instances dataset = source.getDataSet();
// set class
dataset.setClassIndex(0);
// build model
**LinearRegression lr = new LinearRegression();**
lr.buildClassifier(dataset);
System.out.println(lr);
Right after LinearRegression instantiation I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError:
no/uib/cipr/matrix/Matrix at
weka_prediction.Main_LinearRegression.main(Main_LinearRegression.java:22)
Caused by: java.lang.ClassNotFoundException: no.uib.cipr.matrix.Matrix
at java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more
I am using weka 3.8.
any ideas? thanks in advance
There is a problem with loading weka.core. You just need to go to the weka repository and download and add the following jars:
mtj.jar
arpack_combined_all.jar
core.jar
See more details here:
Solved!
instead of 3.8, I am now using 3.6 from here:
http://grepcode.com/project/repo1.maven.org/maven2/nz.ac.waikato.cms.weka/weka-stable/
For anyone who are trying to run Weka as a tool. When you downloaded the weka archive, unzip it, you will find the weka.jar. And then just do what #Kirill Karmazin said in the comment in here. unzip the 3 jars arpack_combined.jar, core.jar and mtj.jar and put them alongside with weka.jar.
Then run java -cp * weka.gui.GUIChooser to run the Weka GUI.
Rather than extracting the MTJ and arpack libraries, simply use Weka's package manager to sort this out for you. It will initialize package management and, if necessary, add these internal jars to its classpath automatically.
You do this by calling the loadPackages method of the weka.core.WekaPackageManager class.
Here is an example:
import weka.core.converters.ConverterUtils.DataSource;
import weka.core.Instances;
import weka.core.WekaPackageManager;
import weka.classifiers.functions.LinearRegression;
public class LR {
public static void main(String[] args) throws Exception {
// load packages and MTJ/arpack libraries (if necessary)
WekaPackageManager.loadPackages(false);
// load dataset
DataSource source = new DataSource(args[0]);
Instances dataset = source.getDataSet();
// set class
dataset.setClassIndex(dataset.numAttributes() - 1);
// build model
LinearRegression lr = new LinearRegression();
lr.buildClassifier(dataset);
System.out.println(lr);
}
}
Related
I am trying to generate documentation using the core generation API (as described here https://www.m2doc.org/ref-doc/3.1.0/index.html#core-generation-api). But I have the following error:
Couldn't find the 'isRepresentationDescriptionName()' service.
(It works fine when I use the genconf not programmatically).
I tried to add the SiriusServices using SiriusServiceConfigurator, but didn't manage to solve this issue.
Or maybe is it because I didn't add the SiriusSession option that refers to the .aird file?
I have looked at how new services are added in the newEnvironmentWithDefaultServices work but it is seems not applicable for SiriusServices.
final IQueryEnvironment queryEnvironment = org.eclipse.acceleo.query.runtime.Query
.newEnvironmentWithDefaultServices(null);
final Monitor monitor = new BasicMonitor.Printing(System.out);
final ResourceSet resourceSetForModels = session.getTransactionalEditingDomain().getResourceSet();
resourceSetForModels.createResource(modelUri);
try (DocumentTemplate template = M2DocUtils.parse(resourceSetForModels.getURIConverter(), templateURI,
queryEnvironment, classProvider, monitor)) {
final Map<String, Object> variable = new HashMap<>();
M2DocUtils.generate(template, queryEnvironment, variable, resourceSetForModels, outputURI, monitor);
...
Thanks
The Sirius related services need the Sirius Session. The Session is initialized using the SiriusSession option in the .genconf file. It should be set to an URI referencing the .aird file. In the class M2DocUtils you have several methods to create an IQueryEnvironment that take a Map of String where you can add the SiriusSession option, for instance:
M2DocUtils.getQueryEnvironment(ResourceSet, URI, Map<String, String>)
Note that your code needs to be ran inside of Eclipse, not a standalone java program.
namespace Admin\Shell;
use Cake\Console\Shell;
class AdminAlertShell extends Shell{
...
...
}
Here 'Admin' is plugin, So I created this file inside the plugins folder structure.
File path : /plugins/Admin/src/Shell/AdminAlertShell.php
Tried to run this in CLI
bin/cake admin_alert
But an exception throws
Exception: Unknown command cake admin_alert. Run cake --help to get the list of valid commands. in [localpath/vendor/cakephp/cakephp/src/Console/CommandRunner.php, line 346]
It was working. But I don't know what happened to this. I had upgraded cakephp 3.5 to 3.7. But, I am not sure this caused the issue.
I just tracked down the source of the issue in my project.
Inside my plugin there was a file: src/Plugin.php
Inside this class there was the following lines of code:
/**
* #inheritDoc
*/
public function console(CommandCollection $commands): CommandCollection
{
// Add console commands here.
return $commands;
}
This was probably generated via bake.
I saw that the parent was not called. In the path is added in the parent.
Change this method to look like this:
/**
* #inheritDoc
*/
public function console(CommandCollection $commands): CommandCollection
{
// Add console commands here.
$commands = parent::console($commands);
return $commands;
}
Now the parent is called and the path is added to the command collection.
As a side note I also see the middleware is not calling its parent.
Think it would be a good idea to fix that one aswell.
As an alternative you can just clear out the class and all defaults should be used.
Hope this saves someone the hours it cost me to figure this one out.
I am trying to plot maps using Cartopy offline. I've found this post:
Location of stored offline data for cartopy
However, after changing cartopy.config['data_dir'] to 'C:/...' where the downloaded files are located, when I try to draw coastlines, it still wants to download the map.
cartopy.config['data_dir'] = '.../CartopyMaps'
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
The console says :
Downloading:
http://naciscdn.org/naturalearth/110m/physical/ne_110m_coastline.zip
However, I have ne_110m_coastline dbf, shp, and shx files in .../CartopyMaps/shapefiles/natural_earth/physical/
Why does Cartopy not see my local maps and how can I help it?
Try using the "pre_existing_data_dir" path instead of the "data_dir".
from os.path import expanduser
import cartopy
cartopy.config['pre_existing_data_dir'] = expanduser('~/cartopy-data/')
i had the similar problem and was confused for quite a while. after i downloaded the whole offline dataset and put them in the right dir, after runing the code
...
states = NaturalEarthFeature(category="cultural", scale="50m",
facecolor="none",
name="admin_1_states_provinces_shp")
...
the console still says:
Downloading:
...50m/cultural/ne_50m_admin_1_states_provinces_lines_shp.zip
however, i found there is a slight difference between the file ne_50m_admin_1_states_provinces_lines.shp i downloaded and the file ne_50m_admin_1_states_provinces_lines_shp.zip cartopy tries to acquire ('_shp').
therefore i changed the command into this and it worked:
states = NaturalEarthFeature(category="cultural", scale="50m",
facecolor="none",
name="admin_1_states_provinces")
I am writing a program in Processing on Raspberrypi(Raspbian), to import a 3D STL image file. It is working perfectly on Microsoft (windows7) & Linux(Ubuntu) platform but I am struggling to run same program on Raspberrypi (Raspbian) platform.
I am getting below Error at size(600,600,P3D) when I run this program on Raspberrypi...
Coding
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.processing.*;
TriangleMesh mesh;
ToxiclibsSupport gfx;
void setup() {
size(600,600,P3D);
mesh=(TriangleMesh)new STLReader().loadBinary(sketchPath("check.stl"),STLReader.TRIANGLEMESH);
gfx=new ToxiclibsSupport(this);
}
void draw() {
background(51);
lights();
translate(width/2,height/2,0);
rotateX(mouseY*0.01);
rotateY(mouseX*0.01);
gfx.origin(new Vec3D(),200);
noStroke();
gfx.mesh(mesh,false,10);
}
Error
java.lang.NoClassDefFoundError: javax/media/opengl/GLException
at processing.opengl.PGraphicsOpenGL.createPGL(PGraphicsOpenGL.java:1744)
at processing.opengl.PGraphicsOpenGL.<init>(PGraphicsOpenGL.java:518)
at processing.opengl.PGraphics3D.<init>(PGraphics3D.java:37)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at processing.core.PApplet.makeGraphics(PApplet.java:1919)
at processing.core.PApplet.size(PApplet.java:1771)
at processing.core.PApplet.size(PApplet.java:1742)
at project5.setup(project5.java:27)
at processing.core.PApplet.handleDraw(PApplet.java:2361)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
at processing.core.PApplet.run(PApplet.java:2256)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ClassNotFoundException: javax.media.opengl.GLException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 15 more
The issue with Processing is that currently there is no 3D implementation because Raspberry PI needs an OPENGL_ES renderer.
Currently you can only render in 2D (e.g. size(200,200,JAVA2D);).
There is actually an OPENGL_ES renderer in Processing but it's for the Android mode and it has dependencies on the android SDK. As far as I know, there isn't any Processing OPENGL_ES renderer you can use on Raspberry PI at the moment(if someone knows of one, please let me know). In theory how ever, it should be possible to strip out the android dependencies from the Android PGraphics class, but feels like a risky move (especially if you have a tight deadline).To get started you may want to look EGL in java running on Rasperry Pi.
I would recommend using OpenFrameworks instead in this case, if displaying an STL file is all you need. I've modified an existing STL addon for OpenFramworks and tested it: the performance is great on the Raspberry PI. Although it's c++, the project is inspired by Processing and a lot of the functions will sound very familiar.
Once you setup OpenFramworks you can download ofxSTLModel and compile the example(I've updated it to run on Raspberry PI). Press any key to toggle wireframe view.
Update
Now there is an experimental Raspian image including Processing 3 with 3D support. Check out this thread
I have a small command line utility project that I'm using Maven to manage. The utility is a very simple app to populate a Velocity template and dump the results to a new file. My problem is where to put my Velocity templates. When I put them in src/test/resources/foo/bar/baz, mvn test fails because it can't find the referenced template, even though it is clearly there in target/classes/foo/bar/baz, which is where the .class file for the test and the class under test are located. If I put the template in the top-level directory of the project, the test passes, but then I'm not following the Maven project structure, and I suspect that the actual packaged .jar file wouldn't function. What am I missing?
UPDATE:
Method under test:
public final void mergeTemplate(final String templateFileName, final Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException, Exception {
Velocity.init();
Velocity.mergeTemplate(templateFileName, Charset.defaultCharset().name(), context(), writer);
}
Test method:
#Test
public void testMergeTemplate() throws Exception {
final FooGenerator generator = new FooGenerator();
final StringWriter writer = new StringWriter();
generator.mergeTemplate("foo.yaml", writer);
Assert.assertEquals("Something went horribly, horribly wrong.", EXPECTED_RESULT, writer.toString().trim());
}
The only place I can place foo.yaml and have the tests pass is in the root directory of the project, i.e., as a peer of src and target.
You can programmatically configure TEMPLATE_ROOT as follows:
Properties props = new Properties();
props.put("file.resource.loader.path", templateRootDir);
VelocityEngine engine = new VelocityEngine();
engine.init(props);
engine.evaluate(...);
You should put them in src/main/resources/foo/bar/baz because they need to be included in the main jar file.
So it turns out that instead of using something like
generator.mergeTemplate("foo.yaml", writer);
I should use something like
InputStream fooStream = getClass().getResourceAsStream("foo.yaml");
generator.mergeTemplate(fooStream, writer);
You could just configure Velocity to use the ClasspathResourceLoader, instead of the default FileResourceLoader.
I have tried Velocity.setProperty() to set the properties similar to what was said above by #Jin Kim and was able to run it.
VelocityEngine ve = new VelocityEngine();
ve.setProperty(RunTimeConstants.RESOURCE_LOADER,"file");
ve.setProperty("file.resource.loader.path",templaterootdir);
ve.init();